Last change
on this file since 124 was
44,
checked in by mszubert, 15 years ago
|
cecj, framsticks and games packages imported
|
File size:
817 bytes
|
Line | |
---|
1 | package games.scenarios; |
---|
2 | |
---|
3 | import games.BoardGame; |
---|
4 | import games.GameMove; |
---|
5 | import games.Player; |
---|
6 | |
---|
7 | import java.util.List; |
---|
8 | |
---|
9 | public class SimpleTwoPlayersGameScenario implements GameScenario { |
---|
10 | |
---|
11 | private Player[] players; |
---|
12 | |
---|
13 | public SimpleTwoPlayersGameScenario(Player[] players) { |
---|
14 | this.players = players; |
---|
15 | } |
---|
16 | |
---|
17 | public int play(BoardGame game) { |
---|
18 | while (!game.endOfGame()) { |
---|
19 | List<? extends GameMove> moves = game.findMoves(); |
---|
20 | if (!moves.isEmpty()) { |
---|
21 | GameMove bestMove = null; |
---|
22 | double bestEval = Double.NEGATIVE_INFINITY; |
---|
23 | for (GameMove move : moves) { |
---|
24 | double eval = game.evalMove(players[game.getCurrentPlayer()], move); |
---|
25 | if (eval > bestEval) { |
---|
26 | bestEval = eval; |
---|
27 | bestMove = move; |
---|
28 | } |
---|
29 | } |
---|
30 | game.makeMove(bestMove); |
---|
31 | } |
---|
32 | game.switchPlayer(); |
---|
33 | } |
---|
34 | return game.getOutcome(); |
---|
35 | } |
---|
36 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.