Ejemplo n.º 1
0
func (t *testPlayersSuite) TestNextPlayer() {
	players := playersSuiteSetup()

	player1 := NewHumanPlayer(game.X, game.NewTictactoeBoard(), io.NewStdPrompter())
	player2 := NewHumanPlayer(game.O, game.NewTictactoeBoard(), io.NewStdPrompter())
	players.Add(player1)
	players.Add(player2)

	t.Equal(player2, players.Next(player1))
	t.Equal(player1, players.Next(player2))
	t.Equal(player1, players.Next(nil))
}
Ejemplo n.º 2
0
func aiPlayerSuiteSetup() (board game.Board, player *Ai) {
	prompter := io.NewStdPrompter()
	board = game.NewTictactoeBoard()
	p := NewAiPlayer(game.X, board, prompter)
	player = p.(*Ai)
	return
}
Ejemplo n.º 3
0
func (t *testPlayersSuite) TestAddPlayer() {
	players := playersSuiteSetup()

	human := NewHumanPlayer(game.X, game.NewTictactoeBoard(), io.NewStdPrompter())
	players.Add(human)
	t.Equal(1, len(players.list))

	human2 := NewHumanPlayer(game.X, game.NewTictactoeBoard(), io.NewStdPrompter())
	players.Add(human2)
	t.Equal(2, len(players.list))

	human3 := NewHumanPlayer(game.X, game.NewTictactoeBoard(), io.NewStdPrompter())
	err := players.Add(human3)
	t.Equal(fmt.Sprint(err), "Can only have two players")
	t.Equal(2, len(players.list))
}
Ejemplo n.º 4
0
func NewTictactoe(prompter io.Prompter) (t *Tictactoe) {
	board := game.NewTictactoeBoard()
	rules := game.NewTictactoeRules(board)
	players := player.NewTictactoePlayers()

	t = &Tictactoe{board: board, rules: rules, players: players, prompter: prompter}
	return
}
Ejemplo n.º 5
0
func (t *testPlayersSuite) TestMakeAndAdd() {
	players := playersSuiteSetup()
	board := game.NewTictactoeBoard()
	prompter := io.NewStdPrompter()

	players.MakeAndAdd("human", "human", board, prompter)
	t.Equal(2, len(players.list))
}
Ejemplo n.º 6
0
func (t *testPlayersSuite) TestMake() {
	players := playersSuiteSetup()
	mark := game.X
	board := game.NewTictactoeBoard()
	prompter := io.NewStdPrompter()

	player := players.Make("human", mark, board, prompter)
	_, err := player.(*Human)
	t.Nil(err, "should creating human player")
}
Ejemplo n.º 7
0
func playerSuiteSetup() (board game.Board, player Player) {
	board = game.NewTictactoeBoard()
	prompter := io.NewStdPrompter()
	player = NewHumanPlayer(game.X, board, prompter)
	return
}