-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.py
63 lines (53 loc) · 1.82 KB
/
Player.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
#
# Copyright 2018 Carsten Friedrich ([email protected]).
# All rights reserved
#
from abc import ABC, abstractmethod
from Board import Board, GameResult
class Player(ABC):
"""
Abstract class defining the interface we expect any Tic Tac Toe player class to implement.
This will allow us to pit various different implementation against each other
"""
def __init__(self):
"""
Nothing to do here apart from calling our super class
"""
super().__init__()
@abstractmethod
def move(self, board: Board) -> (GameResult, bool):
"""
The player should make a move on board `board` and return the result.
The return result can usually be passed on from the corresponding method in the board class.
:param board: The board to make a move on
:return: The GameResult after this move, Flag to indicate whether the move finished the game
"""
pass
@abstractmethod
def final_result(self, result: GameResult):
"""
This method will be called after the game has finished.
It allows the player to ponder its game move choices
and learn from the experience
:param result: The result of the game
"""
pass
@abstractmethod
def new_game(self, side: int):
"""
This method will be called before a game starts. It allows the players to get ready for the game and also tells
which side it is on.
:param side: The side the player will play in the new game
"""
pass
# Additional method for printing purposes
@abstractmethod
def name(self):
"""
Gives the name of this algorithm
"""
pass
# Additional method for creatihng a non-trained agent
@abstractmethod
def copy(self):
pass