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))
}
Example #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
}
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))
}
func (t *testPlayersSuite) TestMakeAndAdd() {
	players := playersSuiteSetup()
	board := game.NewTictactoeBoard()
	prompter := io.NewStdPrompter()

	players.MakeAndAdd("human", "human", board, prompter)
	t.Equal(2, len(players.list))
}
Example #5
0
func main() {
	prompter := io.NewStdPrompter()

	firstTime := true
	for firstTime || play(prompter) {
		firstTime = false
	}

	prompter.Printer().Println("Goodbye!")
}
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")
}
Example #7
0
func playerSuiteSetup() (board game.Board, player Player) {
	board = game.NewTictactoeBoard()
	prompter := io.NewStdPrompter()
	player = NewHumanPlayer(game.X, board, prompter)
	return
}