Ejemplo n.º 1
0
// Run runs n mancala.Games where agent1 plays as player 1 against agent 2 who
// plays as player 2.
func Run(
	agent1Constructor, agent2Constructor ai.AgentConstructor,
	n int,
) *Result {
	result := NewResult(agent1Constructor(), agent2Constructor())
	for i := 0; i < n; i++ {
		result.add(
			mancala.FinishGame(
				agent1Constructor(),
				agent2Constructor(),
			),
		)
	}
	return result
}
Ejemplo n.º 2
0
func Example() {
	result := mancala.FinishGame(ExamplePlayer{}, ExamplePlayer{})
	fmt.Println(result)
	// Output:
	// 5  4  3  2  1  0
	//          <----------------
	// Player 1  0  0  0  0  0  1
	//           0  0  0  0  0  5 Player 2
	//          ---------------->
	//           0  1  2  3  4  5
	//
	// Player 1 Score: 15
	// Player 2 Score: 27
	//
	// Result of last move:
	// Last move: 4
	// Move count: 84
}
Ejemplo n.º 3
0
// TestFinishGame tests that mancala.FinishGame returns the mancala.Result from
// the  beginning of a mancala.Game described by a shortPlayer.
func TestFinishGame(t *testing.T) {
	t.Parallel()
	player1 := newShortPlayer(mancala.Player1)
	player2 := newShortPlayer(mancala.Player2)
	actual := mancala.FinishGame(player1, player2)
	expected := mancala.NewResult(
		player1.expectedBoard(),
		player1.expectedWinner(),
		player1.expectedMoveCount(),
		player1.expectedLastMove(),
		nil,
	)
	if actual != expected {
		t.Errorf(
			"FinishGame(\n\t%v, \n\t%v,\n) = \n%v, want \n%v",
			player1,
			player2,
			actual,
			expected,
		)
	}
}
Ejemplo n.º 4
0
// BenchmarkMancala runs 10000 Oware games with fastPlayers.
//
// The benchmark should be used to profile the platform. The goal after
// profiling will be to reduce memory allocations and decrease run time.
func BenchmarkMancala(b *testing.B) {
	for i := 0; i < 10000; i++ {
		mancala.FinishGame(fastPlayer{}, fastPlayer{})
	}
}