Esempio n. 1
0
// NewRootState creates the root State of a mancala game search tree with a
// mancala.Referee and mancala.PlayerIndex.
func NewRootState(
	referee *mancala.Referee,
	index mancala.PlayerIndex,
) *State {
	return &State{
		parent:      nil,
		referee:     referee,
		information: NewInformation(referee.Board(), index.Other(), -1),
	}
}
Esempio n. 2
0
// Play makes a move for an ExamplePlayer.
//
// If no legal moves can be found, an invalid mancala.HouseIndex is returned
// along with an error.
func (player ExamplePlayer) Play(
	referee *mancala.Referee,
	index mancala.PlayerIndex,
) (mancala.HouseIndex, error) {
	for i := 0; i < mancala.RowWidth; i++ {
		house := mancala.HouseIndex(i)
		if _, err := referee.SimulateMove(index, house); err == nil {
			return house, nil
		}
	}
	return -1, fmt.Errorf(
		"ExamplePlayer couldn't find a legal HouseIndex as %v on "+
			"board \n%v",
		index,
		referee.Board(),
	)
}
Esempio n. 3
0
// Play makes a move for a fastPlayer.
//
// If there are no legal moves, an invalid mancala.HouseIndex is returned along
// with an error stating that the fastPlayer couldn't find a valid
// mancala.houseIndex.
func (fast fastPlayer) Play(
	referee *mancala.Referee,
	player mancala.PlayerIndex,
) (mancala.HouseIndex, error) {
	for i := 0; i < mancala.RowWidth; i++ {
		house := mancala.HouseIndex(i)
		if _, err := referee.SimulateMove(player, house); err == nil {
			return house, nil
		}
	}
	return -1, fmt.Errorf(
		"fastPlayer couldn't find a legal HouseIndex as %v on board\n"+
			"%v",
		player,
		referee.Board(),
	)
}