Documentation ¶
Overview ¶
Package hexplayer - In this file are implemented functions that can be called by any coputer player when the game is decided.
Index ¶
- func OpenConn(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)
- type AbPlayer
- func (ap *AbPlayer) EndGame(lastAction *hex.Action, won bool)
- func (ap AbPlayer) GetColor() hex.Color
- func (ap AbPlayer) GetNumberOfWins() int
- func (ap AbPlayer) GetType() PlayerType
- func (ap *AbPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
- func (ap *AbPlayer) NextAction() (*hex.Action, error)
- func (ap *AbPlayer) PrevAction(prevAction *hex.Action)
- type HexPlayer
- type HumanPlayer
- func (hp *HumanPlayer) EndGame(lastAction *hex.Action, won bool)
- func (hp HumanPlayer) GetColor() hex.Color
- func (hp HumanPlayer) GetNumberOfWins() int
- func (hp HumanPlayer) GetType() PlayerType
- func (hp HumanPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
- func (hp HumanPlayer) NextAction() (*hex.Action, error)
- func (hp HumanPlayer) PrevAction(prevAction *hex.Action)
- type HybridPlayer
- func (hp *HybridPlayer) EndGame(lastAction *hex.Action, won bool)
- func (hp HybridPlayer) GetColor() hex.Color
- func (hp HybridPlayer) GetNumberOfWins() int
- func (hp HybridPlayer) GetType() PlayerType
- func (hp *HybridPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
- func (hp *HybridPlayer) NextAction() (*hex.Action, error)
- func (hp *HybridPlayer) PrevAction(prevAction *hex.Action)
- type MCTSplayer
- func (mp *MCTSplayer) EndGame(lastAction *hex.Action, won bool)
- func (mp MCTSplayer) GetColor() hex.Color
- func (mp MCTSplayer) GetNumberOfWins() int
- func (mp MCTSplayer) GetType() PlayerType
- func (mp *MCTSplayer) InitGame(boardSize int, firstPlayer hex.Color) error
- func (mp *MCTSplayer) NextAction() (*hex.Action, error)
- func (mp *MCTSplayer) PrevAction(prevAction *hex.Action)
- type PlayerType
- type RandPlayer
- func (rp *RandPlayer) EndGame(lastAction *hex.Action, won bool)
- func (rp RandPlayer) GetColor() hex.Color
- func (rp RandPlayer) GetNumberOfWins() int
- func (rp RandPlayer) GetType() PlayerType
- func (rp *RandPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
- func (rp *RandPlayer) NextAction() (*hex.Action, error)
- func (rp *RandPlayer) PrevAction(prevAction *hex.Action)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AbPlayer ¶
type AbPlayer struct { Color hex.Color // Player's color Webso *websocket.Conn // Websocket connecting server and client // contains filtered or unexported fields }
AbPlayer represents a computer player that uses alpha-beta pruning for selecting moves
func CreateAbPlayer ¶
func CreateAbPlayer(c hex.Color, webso *websocket.Conn, t time.Duration, allowResignation bool, patFileName string, createTree bool, subtype PlayerType) *AbPlayer
CreateAbPlayer creates a new player
func (AbPlayer) GetNumberOfWins ¶
GetNumberOfWins returns the number of wins for this player
func (AbPlayer) GetType ¶
func (ap AbPlayer) GetType() PlayerType
GetType returns the type of the player
func (*AbPlayer) NextAction ¶
NextAction returns an action to be performed. It returns nil when the player decides to resign.
func (*AbPlayer) PrevAction ¶
PrevAction accepts opponent's last action
type HexPlayer ¶
type HexPlayer interface { InitGame(int, hex.Color) error // Initializes game with a grid of a given size and first player PrevAction(*hex.Action) // Acepts opponent's last action NextAction() (*hex.Action, error) // Returns an action to be performed EndGame(*hex.Action, bool) // Accepts last action in the game and boolean value indicating whether the player has won or not GetColor() hex.Color // Gets the color of the player GetNumberOfWins() int // Returns the number of wins GetType() PlayerType // Returns the type of the player }
HexPlayer represents a player of hex that can be either human or computer.
type HumanPlayer ¶
type HumanPlayer struct { Color hex.Color // Player's color Webso *websocket.Conn // Websocket connecting server and client // contains filtered or unexported fields }
HumanPlayer accepts client's (human's) moves. It uses a websocket to connect to the client.
func CreateHumanPlayer ¶
func CreateHumanPlayer(conn *websocket.Conn, color hex.Color) *HumanPlayer
CreateHumanPlayer creates a human player with given websocket and color of the player.
func (*HumanPlayer) EndGame ¶
func (hp *HumanPlayer) EndGame(lastAction *hex.Action, won bool)
EndGame sends the following information to the client: last action made in the game, boolean value indicating whether the player has won or not.
func (HumanPlayer) GetColor ¶
func (hp HumanPlayer) GetColor() hex.Color
GetColor returns the color of the player
func (HumanPlayer) GetNumberOfWins ¶
func (hp HumanPlayer) GetNumberOfWins() int
GetNumberOfWins returns the number of wins for the player
func (HumanPlayer) GetType ¶
func (hp HumanPlayer) GetType() PlayerType
GetType returns the type of the player
func (HumanPlayer) InitGame ¶
func (hp HumanPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
InitGame initializes the game. It sends board size and player's color to the client and waits for replay.
func (HumanPlayer) NextAction ¶
func (hp HumanPlayer) NextAction() (*hex.Action, error)
NextAction returns an action to be performed.
func (HumanPlayer) PrevAction ¶
func (hp HumanPlayer) PrevAction(prevAction *hex.Action)
PrevAction accepts last opponent's action
type HybridPlayer ¶
HybridPlayer represents a computer player that combines strategies of MCTS and AB
func CreateHybridPlayer ¶
func CreateHybridPlayer(c hex.Color, t time.Duration, allowResignation bool, patFileName string, ABsubtype PlayerType, changeTypeAt int) *HybridPlayer
CreateHybridPlayer creates a new player
func (*HybridPlayer) EndGame ¶
func (hp *HybridPlayer) EndGame(lastAction *hex.Action, won bool)
EndGame accepts the result of the game
func (HybridPlayer) GetColor ¶
func (hp HybridPlayer) GetColor() hex.Color
GetColor returns the color of the player
func (HybridPlayer) GetNumberOfWins ¶
func (hp HybridPlayer) GetNumberOfWins() int
GetNumberOfWins returns the number of wins for this player
func (HybridPlayer) GetType ¶
func (hp HybridPlayer) GetType() PlayerType
GetType returns the type of the player
func (*HybridPlayer) InitGame ¶
func (hp *HybridPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
InitGame initializes the game
func (*HybridPlayer) NextAction ¶
func (hp *HybridPlayer) NextAction() (*hex.Action, error)
NextAction returns an action to be performed
func (*HybridPlayer) PrevAction ¶
func (hp *HybridPlayer) PrevAction(prevAction *hex.Action)
PrevAction accepts opponent's last action
type MCTSplayer ¶
MCTSplayer represents a computer player that uses only MCTS for selecting moves
func CreateMCTSplayer ¶
CreateMCTSplayer creates a new player
func (*MCTSplayer) EndGame ¶
func (mp *MCTSplayer) EndGame(lastAction *hex.Action, won bool)
EndGame accepts the result of the game
func (MCTSplayer) GetColor ¶
func (mp MCTSplayer) GetColor() hex.Color
GetColor returns the color of the player
func (MCTSplayer) GetNumberOfWins ¶
func (mp MCTSplayer) GetNumberOfWins() int
GetNumberOfWins returns the number of wins for this player
func (MCTSplayer) GetType ¶
func (mp MCTSplayer) GetType() PlayerType
GetType returns the type of the player
func (*MCTSplayer) InitGame ¶
func (mp *MCTSplayer) InitGame(boardSize int, firstPlayer hex.Color) error
InitGame initializes the game
func (*MCTSplayer) NextAction ¶
func (mp *MCTSplayer) NextAction() (*hex.Action, error)
NextAction returns an action to be performed. It returns nil when the player decides to resign.
func (*MCTSplayer) PrevAction ¶
func (mp *MCTSplayer) PrevAction(prevAction *hex.Action)
PrevAction accepts opponent's last action
type PlayerType ¶
type PlayerType byte
const ( Unknown PlayerType = 0 HumanType PlayerType = 1 RandType PlayerType = 2 MctsType PlayerType = 3 AbDtType PlayerType = 4 AbLrType PlayerType = 5 HybridType PlayerType = 6 )
enum for player types
func GetPlayerTypeFromString ¶
func GetPlayerTypeFromString(t string) PlayerType
func (PlayerType) String ¶
func (t PlayerType) String() string
type RandPlayer ¶
RandPlayer represents a computer player that randomly selects actions
func CreateRandPlayer ¶
func CreateRandPlayer(c hex.Color) *RandPlayer
CreateRandPlayer creates a new player
func (*RandPlayer) EndGame ¶
func (rp *RandPlayer) EndGame(lastAction *hex.Action, won bool)
EndGame accepts the result of the game
func (RandPlayer) GetColor ¶
func (rp RandPlayer) GetColor() hex.Color
GetColor returns the color of the player
func (RandPlayer) GetNumberOfWins ¶
func (rp RandPlayer) GetNumberOfWins() int
GetNumberOfWins returns the number of wins for this player
func (RandPlayer) GetType ¶
func (rp RandPlayer) GetType() PlayerType
GetType returns the type of the player
func (*RandPlayer) InitGame ¶
func (rp *RandPlayer) InitGame(boardSize int, firstPlayer hex.Color) error
InitGame initializes the game
func (*RandPlayer) NextAction ¶
func (rp *RandPlayer) NextAction() (*hex.Action, error)
NextAction returns a randomly chosen action to be performed
func (*RandPlayer) PrevAction ¶
func (rp *RandPlayer) PrevAction(prevAction *hex.Action)
PrevAction accepts opponent's last action