Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Self-Training #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gameLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def move(self, pos, play_yourself=False):
copy_of_board[row][column] = self.turn
possibleMoves.append((row,column,self.predict(copy_of_board)))
break

if possibleMoves == []:
return
row, col, prob = possibleMoves[0]
for i in range (len(possibleMoves)) :
if possibleMoves[i][2] > prob:
Expand Down Expand Up @@ -130,11 +131,18 @@ def isGameFinished (self):
with open("Data/dataset.csv", "a+") as f:
for row in self.board:
for element in row :
f.write(str(element)+',')
f.write(str(element) + ',')
if self.winner == 'Player1':
f.write(str(1))
elif self.winner == 'Player2' or 'Computer':
f.write(str(2))
else:
f.write(str(0))
f.write('\n')
else:
board = self.board
for i in range(len(board)):
if 0 in board[i]:
return
self.game_over = True

15 changes: 15 additions & 0 deletions selftrain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from gameLogic import Game
from train import main
game = Game()
n = int(input())
for i in range(n):
while True:
game.isGameFinished()
if game.game_over:
main()
print(i + 1)
game = Game()
break
game.move(game.board, True)
game.changeTurn()