AI-Evolve-Befunge
view release on metacpan or search on metacpan
t/08physics_othello.t view on Meta::CPAN
........
........
EOF
# player 1 makes a move
is($othello->make_move($board,1,v(5,3)), 2, "after player 1 moves, player 2 is next");
is($board->as_string(), <<EOF, "after one move");
........
........
........
...xxx..
...ox...
........
........
........
EOF
is($othello->score($board, 1, 1), 4, "score");
is($othello->score($board, 2, 1), 1, "score");
is($othello->over($board), 0, "over");
# player 1 makes another move
is($othello->make_move($board,1,v(2,4)), 0, "after player 1 moves again, the game is won; no moves are valid");
is($board->as_string(), <<EOF, "after two moves");
........
........
........
...xxx..
..xxx...
........
........
........
EOF
is($othello->score($board, 1, 1), 6, "score");
is($othello->score($board, 2, 1), 0, "score");
is($othello->over($board), 1, "over");
is($othello->won($board), 1, "game is won by player 1");
$$board{b} = [
[0,0,0,0,0,0,0,0], # 0
[0,0,0,0,0,0,0,0], # 1
[0,0,0,0,0,0,0,0], # 2
[0,0,1,1,1,1,1,0], # 3
[0,0,1,2,1,0,1,0], # 4
[0,0,1,1,1,1,1,0], # 5
[0,0,0,0,0,0,0,0], # 6
[0,0,0,0,0,0,0,0], # 7
# 0 1 2 3 4 5 6 7
];
is($othello->can_pass($board,1), 1, "player 1 has no valid moves, can pass");
is($othello->make_move($board,2,v(5,4)), 2, "player 1 has to pass, player 2 moves again");
$$board{b} = [
[0,0,0,0,0,0,0,0], # 0
[0,0,0,0,0,0,0,0], # 1
[0,2,2,2,0,1,1,1], # 2
[0,2,0,2,0,1,1,1], # 3
[0,2,1,2,0,1,1,1], # 4
[0,2,2,2,0,1,1,1], # 5
[0,0,0,0,0,0,0,0], # 6
[0,0,0,0,0,0,0,0], # 7
# 0 1 2 3 4 5 6 7
];
is($othello->won( $board), 0, "game not won yet");
is($othello->over($board), 0, "game not over yet");
is($othello->make_move($board,2,v(2,3)), 0, "no valid moves, equal scores, tie game");
$$board{b} = [
[0,0,0,0,0,0,0,0], # 0
[0,0,0,0,0,0,0,0], # 1
[0,2,2,2,0,0,0,0], # 2
[0,2,2,2,0,0,0,0], # 3
[0,2,2,2,0,0,0,0], # 4
[0,2,2,2,0,0,0,0], # 5
[0,0,0,0,0,0,0,0], # 6
[0,0,0,0,0,0,0,0], # 7
# 0 1 2 3 4 5 6 7
];
is($othello->won($board), 2, "nothing left of player 1");
$$board{b} = [
[0,0,0,0,0,0,0,0], # 0
[0,0,0,0,0,0,0,0], # 1
[0,0,0,0,0,0,0,0], # 2
[0,2,2,0,0,1,0,0], # 3
[0,0,0,0,0,0,0,0], # 4
[0,0,0,0,0,0,0,0], # 5
[0,0,0,0,0,0,0,0], # 6
[0,0,0,0,0,0,0,0], # 7
# 0 1 2 3 4 5 6 7
];
is($othello->won($board), 2, "player 2 still wins");
$$board{b} = [
[0,0,0,0,0,0,0,0], # 0
[0,0,0,0,0,0,0,0], # 1
[0,0,0,0,0,0,0,0], # 2
[0,2,0,0,1,1,0,0], # 3
[0,0,0,0,0,0,0,0], # 4
[0,0,0,0,0,0,0,0], # 5
[0,0,0,0,0,0,0,0], # 6
[0,0,0,0,0,0,0,0], # 7
# 0 1 2 3 4 5 6 7
];
is($othello->won($board), 1, "player 1 still wins");
BEGIN { $num_tests += 24 };
# in_bounds
dies_ok(sub { $othello->in_bounds() }, "in_bounds with no argument");
BEGIN { $num_tests += 1 };
BEGIN { plan tests => $num_tests };
( run in 0.676 second using v1.01-cache-2.11-cpan-5735350b133 )