@qoderman/

triple5225a5tja59hwq5h8251

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import random
from sklearn import svm
from sklearn.ensemble import RandomForestClassifier


history = [2, 1, 3, 2, 3, 2, 1]
input_data = [[2,3,1,3,3,3,3],[2,2,1,3,3,3,3],[1,1,2,2,3,3,3],[1,3,1,2,2,2,2],[3,1,3,1,2,2,2],[3,1,3,2,1,1,1],[1,2,2,3,1,1,1]]
output_data = [3,3,3,2,2,1,1]
model = svm.SVC()
model.fit(input_data, output_data)


def AIMove():
  data_record = history[-7:]
  current = model.predict([data_record])[0]
  if current == 1:
    return 2
  if current == 2:
    return 3
  return 1

def AIDestroyBot(history):
  history.append(player1)
  input_data.append((history[-8:])[0:-1])
  output_data.append(history[-1])
  model.fit(input_data, output_data)
  
def playerInput():
  return random.randint(1,3)

wins_player1 = 0
wins_player2 = 0
total_ties = 0

for i in range(1, 2500):
  print("Game ", i) 
  player1 = playerInput()
  player2 = AIMove()
  print("Player 1 choice: " + str(player1) + " Player 2 choice: " + str(player2))
  if player1 == 1 and player2 == 2:
    print("Player 2 Won!")
    wins_player2 += 1
  if player1 == 1 and player2 == 3:
    print("Player 1 Won!")
    wins_player1 += 1
  if player1 == 2 and player2 == 1:
    print("Player 1 Won!")
    wins_player1 += 1
  if player1 == 2 and player2 == 3:
    print("Player 2 Won!")
    wins_player2 += 1
  if player1 == 3 and player2 == 1:
    print("Player 2 Won!")
    wins_player2 += 1
  if player1 == 3 and player2 == 2:
    print("Player 1 Won!")
    wins_player1 += 1
  if player1 == player2:
    print("It's a tie!")
    total_ties += 1
  print("Score\n"
    "Player 1: " + str(wins_player1) + " Player 2: " + str(wins_player2) + " Ties: " + str(total_ties))


print("\n\n\n\n--------------------------------")
print("Final score:")
print("Player 1: " + str(wins_player1) + " Player 2: " + str(wins_player2))