Last change
on this file was
193,
checked in by Maciej Komosinski, 11 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
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.