hexplayer

package
v0.0.0-...-db2e5f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2019 License: BSD-2-Clause Imports: 13 Imported by: 3

Documentation

Overview

Package hexplayer - In this file are implemented functions that can be called by any coputer player when the game is decided.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenConn

func OpenConn(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

OpenConn opens a new websocket.

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) EndGame

func (ap *AbPlayer) EndGame(lastAction *hex.Action, won bool)

EndGame accepts the result of the game

func (AbPlayer) GetColor

func (ap AbPlayer) GetColor() hex.Color

GetColor returns the color of the player

func (AbPlayer) GetNumberOfWins

func (ap AbPlayer) GetNumberOfWins() int

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) InitGame

func (ap *AbPlayer) InitGame(boardSize int, firstPlayer hex.Color) error

InitGame initializes the game

func (*AbPlayer) NextAction

func (ap *AbPlayer) NextAction() (*hex.Action, error)

NextAction returns an action to be performed. It returns nil when the player decides to resign.

func (*AbPlayer) PrevAction

func (ap *AbPlayer) PrevAction(prevAction *hex.Action)

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

type HybridPlayer struct {
	Color hex.Color
	// contains filtered or unexported fields
}

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

type MCTSplayer struct {
	Color hex.Color
	// contains filtered or unexported fields
}

MCTSplayer represents a computer player that uses only MCTS for selecting moves

func CreateMCTSplayer

func CreateMCTSplayer(c hex.Color, ef float64, t time.Duration, mbe uint, ar bool) *MCTSplayer

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

type RandPlayer struct {
	Color hex.Color
	// contains filtered or unexported fields
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL