[44] | 1 | package games.league; |
---|
| 2 | |
---|
| 3 | import ec.util.MersenneTwisterFast; |
---|
| 4 | import games.Player; |
---|
| 5 | import games.scenarios.GameScenario; |
---|
| 6 | import games.scenarios.RandomizedTwoPlayersGameScenario; |
---|
| 7 | |
---|
| 8 | import java.io.InputStream; |
---|
| 9 | import java.util.Scanner; |
---|
| 10 | |
---|
| 11 | import cecj.app.othello.OthelloBoard; |
---|
| 12 | import cecj.app.othello.OthelloGame; |
---|
| 13 | import cecj.app.othello.OthelloPlayer; |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | public class RandomPerformanceMeter { |
---|
| 17 | |
---|
| 18 | private OthelloPlayer player; |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | public void readPlayer(InputStream input) { |
---|
| 22 | Scanner s = new Scanner(input); |
---|
| 23 | double[] wpc = new double[64]; |
---|
| 24 | for (int i = 0; i < 64; i++) { |
---|
| 25 | wpc[i] = s.nextDouble(); |
---|
| 26 | } |
---|
| 27 | player = new OthelloPlayer(wpc); |
---|
| 28 | |
---|
| 29 | System.out.println("Player = " + player); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | private int testPlayer(int repeats) { |
---|
| 34 | MersenneTwisterFast rng = new MersenneTwisterFast(System.currentTimeMillis()); |
---|
| 35 | |
---|
| 36 | GameScenario scenario1 = new RandomizedTwoPlayersGameScenario(rng, new Player[] { player, new OthelloPlayer()}, new double[] {0, 1.0}); |
---|
| 37 | GameScenario scenario2 = new RandomizedTwoPlayersGameScenario(rng, new Player[] { new OthelloPlayer(), player}, new double[] {1.0, 0}); |
---|
| 38 | OthelloGame game = new OthelloGame(new OthelloBoard()); |
---|
| 39 | |
---|
| 40 | int sum = 0; |
---|
| 41 | for (int i = 0; i < repeats; i++) { |
---|
| 42 | game.reset(); |
---|
| 43 | sum += ((scenario1.play(game) > 0) ? 1 : 0); |
---|
| 44 | game.reset(); |
---|
| 45 | sum += ((scenario2.play(game) < 0) ? 1 : 0); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | return sum; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * @param args |
---|
| 53 | */ |
---|
| 54 | public static void main(String[] args) { |
---|
| 55 | RandomPerformanceMeter rpm = new RandomPerformanceMeter(); |
---|
| 56 | rpm.readPlayer(System.in); |
---|
| 57 | System.out.println(rpm.testPlayer(500) + " games won out of 1000"); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | } |
---|