Added win condition logic

It was the hardest to implement, but yay, I did it.
This commit is contained in:
otomo otonami 2022-08-07 09:23:10 +03:00
parent a9b8409928
commit 8dd2035167

View File

@ -19,10 +19,31 @@ class GameLogic():
pass pass
def check_for_win(self, playerList): def check_who_win(self):
for player in playerList: # Should have used vectors instead of committing tuples mithosis,
pass # but whatever, it works anyway, and if it works, why code more
# for nothing?
for player in self.playerList:
markList = player.get_markList()
# since every mark is checked, there's no need to go into
# opposite directions, so, there is (0,1) but no (0, -1).
# This twice decreases the amount of computation needed.
directions = ((0, 1), (1, 0), (1,1), (-1, 1))
for mark in markList:
for direction in directions:
if self.is_line(markList, mark, direction):
return player
return False
def is_line(self, markList, mark, direction): # INTERNAL, I guess.
for i in range(1, self.winRowLength):
seeked = (mark[0] + direction[0] * i, mark[1] + direction[1] * i)
if seeked in markList:
continue
else:
return False
return True
def get_time(self): def get_time(self):
return str(datetime.now() - self.startTime) return str(datetime.now() - self.startTime)