acpc_dealer 2.4.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/Brickfile +6 -0
  3. data/README.md +7 -6
  4. data/Rakefile +30 -14
  5. data/acpc_dealer.gemspec +2 -1
  6. data/bin/acpc_dealer +4 -0
  7. data/ext/hand_evaluator/extconf.rb +10 -0
  8. data/lib/acpc_dealer/version.rb +1 -1
  9. data/lib/hand_evaluator.bundle +0 -0
  10. data/spec/dealer_runner_spec.rb +76 -72
  11. metadata +19 -82
  12. data/vendor/project_acpc_server/LICENCE +0 -23
  13. data/vendor/project_acpc_server/Makefile +0 -35
  14. data/vendor/project_acpc_server/README +0 -113
  15. data/vendor/project_acpc_server/README.submission +0 -42
  16. data/vendor/project_acpc_server/acpc_play_match.pl +0 -101
  17. data/vendor/project_acpc_server/bm_run_matches.c +0 -238
  18. data/vendor/project_acpc_server/bm_server.c +0 -1604
  19. data/vendor/project_acpc_server/bm_server.config +0 -78
  20. data/vendor/project_acpc_server/bm_widget.c +0 -230
  21. data/vendor/project_acpc_server/dealer.c +0 -1293
  22. data/vendor/project_acpc_server/evalHandTables +0 -4269
  23. data/vendor/project_acpc_server/example_player.c +0 -204
  24. data/vendor/project_acpc_server/example_player.limit.2p.sh +0 -3
  25. data/vendor/project_acpc_server/example_player.limit.3p.sh +0 -3
  26. data/vendor/project_acpc_server/example_player.nolimit.2p.sh +0 -3
  27. data/vendor/project_acpc_server/example_player.nolimit.3p.sh +0 -3
  28. data/vendor/project_acpc_server/game.c +0 -1792
  29. data/vendor/project_acpc_server/game.h +0 -253
  30. data/vendor/project_acpc_server/holdem.limit.2p.reverse_blinds.game +0 -13
  31. data/vendor/project_acpc_server/holdem.limit.3p.game +0 -13
  32. data/vendor/project_acpc_server/holdem.nolimit.2p.reverse_blinds.game +0 -12
  33. data/vendor/project_acpc_server/holdem.nolimit.3p.game +0 -12
  34. data/vendor/project_acpc_server/kuhn.limit.3p.game +0 -14
  35. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player.sf1.sh +0 -3
  36. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player.sf2.sh +0 -3
  37. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player.sf3.sh +0 -3
  38. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/LICENCE +0 -23
  39. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/Makefile +0 -127
  40. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/README.md +0 -35
  41. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/CExceptionConfig.h +0 -12
  42. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/dealer_connection.c +0 -49
  43. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/dealer_connection.h +0 -22
  44. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/kuhn_3p_equilibrium_player.c +0 -483
  45. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/kuhn_3p_equilibrium_player.h +0 -108
  46. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/main.c +0 -84
  47. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/player_config.c +0 -253
  48. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/src/player_config.h +0 -21
  49. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/support/test_helper.c +0 -45
  50. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/support/test_helper.h +0 -27
  51. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player.c +0 -698
  52. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player_sub_family_1.c +0 -324
  53. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player_sub_family_2.c +0 -262
  54. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/test/test_kuhn_3p_equilibrium_player_sub_family_3.c +0 -177
  55. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/docs/license.txt +0 -30
  56. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/docs/readme.txt +0 -242
  57. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/lib/CException.c +0 -43
  58. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/lib/CException.h +0 -86
  59. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/release/build.info +0 -2
  60. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/cexception/release/version.info +0 -2
  61. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/History.md +0 -27
  62. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/Makefile +0 -8
  63. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/Readme.md +0 -103
  64. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/package.json +0 -9
  65. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/src/commander.c +0 -250
  66. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/src/commander.h +0 -88
  67. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/commander.c/test.c +0 -34
  68. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/colour_prompt.rb +0 -94
  69. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/colour_reporter.rb +0 -39
  70. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/generate_config.yml +0 -36
  71. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/generate_module.rb +0 -202
  72. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/generate_test_runner.rb +0 -316
  73. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/test_file_filter.rb +0 -23
  74. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/auto/unity_test_summary.rb +0 -139
  75. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/docs/Unity Summary.txt +0 -216
  76. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/docs/license.txt +0 -31
  77. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/release/build.info +0 -2
  78. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/release/version.info +0 -2
  79. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/src/unity.c +0 -1146
  80. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/src/unity.h +0 -245
  81. data/vendor/project_acpc_server/kuhn_3p_equilibrium_player/vendor/unity/src/unity_internals.h +0 -546
  82. data/vendor/project_acpc_server/net.c +0 -218
  83. data/vendor/project_acpc_server/net.h +0 -62
  84. data/vendor/project_acpc_server/play_match.pl +0 -99
  85. data/vendor/project_acpc_server/protocol.md +0 -239
  86. data/vendor/project_acpc_server/protocol.odt +0 -0
  87. data/vendor/project_acpc_server/protocol.pdf +0 -0
  88. data/vendor/project_acpc_server/rng.c +0 -139
  89. data/vendor/project_acpc_server/rng.h +0 -63
  90. data/vendor/project_acpc_server/validate_submission.pl +0 -546
@@ -1,23 +0,0 @@
1
- Copyright (C) 2011 by the Computer Poker Research Group, University of Alberta
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- Except as contained in this notice, the name(s) of the above copyright holders
14
- shall not be used in advertising or otherwise to promote the sale, use or other
15
- dealings in this Software without prior written authorization.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
@@ -1,35 +0,0 @@
1
-
2
- THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
3
-
4
- CC = gcc
5
- CFLAGS = -O3 -Wall
6
-
7
- KUHN_3P_E_BASE = kuhn_3p_equilibrium_player
8
- KUHN_3P_E_PLAYER := $(KUHN_3P_E_BASE)
9
- KUHN_3P_E_DIR := $(KUHN_3P_E_BASE)
10
-
11
- PROGRAMS = bm_server bm_widget dealer example_player
12
-
13
- all: $(PROGRAMS) $(KUHN_3P_E_DIR)/$(KUHN_3P_E_PLAYER)
14
-
15
- clean:
16
- rm -f $(PROGRAMS) && cd $(KUHN_3P_E_DIR) && make clean
17
-
18
-
19
- bm_server: bm_server.c game.c game.h rng.c rng.h net.c net.h
20
- $(CC) $(CFLAGS) -o $@ bm_server.c game.c rng.c net.c
21
-
22
- bm_widget: bm_widget.c net.c net.h
23
- $(CC) $(CFLAGS) -o $@ bm_widget.c net.c
24
-
25
- bm_run_matches: bm_run_matches.c net.c net.h
26
- $(CC) $(CFLAGS) -o $@ bm_run_matches.c net.c
27
-
28
- dealer: game.c game.h evalHandTables rng.c rng.h dealer.c net.c net.h
29
- $(CC) $(CFLAGS) -o $@ game.c rng.c dealer.c net.c
30
-
31
- example_player: game.c game.h evalHandTables rng.c rng.h example_player.c net.c net.h
32
- $(CC) $(CFLAGS) -o $@ game.c rng.c example_player.c net.c
33
-
34
- $(KUHN_3P_E_DIR)/$(KUHN_3P_E_PLAYER):
35
- cd $(KUHN_3P_E_DIR) && make
@@ -1,113 +0,0 @@
1
- This README contains information about the server code for the Annual Computer
2
- Poker Competition. Please see the LICENCE file for information regarding the
3
- code's licence.
4
-
5
- ===== Software Requirements =====
6
-
7
- This code was developed and tested for use on Unix based systems. Though it
8
- may work on other platforms, there are no guarantees.
9
-
10
- You will need standard Unix developer tools to build the software including
11
- gcc, and make.
12
-
13
- ===== Getting Started =====
14
-
15
- * Building the code
16
-
17
- The Makefile provides instructions for compiling the code. Running 'make' from
18
- the command line will compile the required programs.
19
-
20
-
21
- * The programs
22
-
23
- dealer - Communicates with agents connected over sockets to play a game
24
- example_player - A sample player implemented in C
25
- play_match.pl - A perl script for running matches with the dealer
26
-
27
- Usage information for each of the programs is available by running the
28
- executable without any arguments.
29
-
30
-
31
- * Playing a match
32
-
33
- The fastest way to start a match is through the play_match.pl script. An
34
- example follows:
35
-
36
- $ ./play_match.pl matchName holdem.limit.2p.reverse_blinds.game 1000 0 Alice ./example_player.limit.2p.sh Bob ./example_player.limit.2p.sh
37
-
38
- After play_match.pl finishes running, there will be two output files for the
39
- dealer and two output files for each player in the game:
40
-
41
- matchName.err - The stderr from dealer including the messages sent to players
42
- matchName.log - The log for the hands played during the match
43
- matchName.playerN.std - stdout from player N
44
- matchName.playerN.err - stderr from player N
45
-
46
- Note, play_match.pl expects player executables that take exactly two arguments:
47
- the server IP followed by the port number. The executable must be specified
48
- such that it is either a path or the executable name if it can be found in your
49
- $PATH.
50
-
51
- If you need to pass specific arguments to you agent, we suggest wrapping it in
52
- another script. play_match.pl will pass any extra arguments to dealer.
53
- Matches can also be started by calling dealer and starting the players
54
- manually. More information on this is contained in the dealer section below.
55
-
56
-
57
- * dealer
58
-
59
- Running dealer will start a process that waits for other players to connect to
60
- it. After starting dealer, it will output something similar to the following:
61
-
62
- $ ./dealer matchName holdem.limit.2p.reverse_blinds.game 1000 0 Alice Bob
63
- 16177 48777
64
- # name/game/hands/seed matchName holdem.limit.2p.reverse_blinds.game 1000 0
65
- #--t_response 10000
66
- #--t_hand 600000
67
- #--t_per_hand 6000
68
-
69
- On the first line of output there should be as many numbers as there are
70
- players in the game (in this case, "16177" and "48777"). These are the ports
71
- the dealer is listening on for players. Note that these ports are specific to
72
- the positions for players in the game.
73
-
74
- Once all the players have connected to the game, the dealer will begin playing
75
- the game and outputting the messages sent to each player. After the end of the
76
- match, you should have a log file called matchName.log in the directory where
77
- dealer was started with the hands that were played.
78
-
79
- Matches can also be started by starting the dealer and connecting the
80
- executables by hand. This can be useful if you want to start your own program
81
- in a way that is difficult to script (such as running it in a debugger).
82
-
83
-
84
- ==== Game Definitions ====
85
-
86
- The dealer takes game definition files to determine which game of poker it
87
- plays. Please see the included game definitions for some examples. The code
88
- for handling game definitions is found in game.c and game.h.
89
-
90
- Game definitions can have the following fields (case is ignored):
91
-
92
- gamedef - the starting tag for a game definition
93
- end gamedef - ending tag for a game definition
94
- stack - the stack size for each player at the start of each hand (for no-limit)
95
- blind - the size of the blinds for each player (relative to the dealer)
96
- raisesize - the size of raises on each round (for limit games)
97
- limit - specifies a limit game
98
- nolimit - specifies a no-limit game
99
- numplayers - number of players in the game
100
- numrounds - number of betting rounds per hand of the game
101
- firstplayer - the player that acts first (relative to the dealer) on each round
102
- maxraises - the maximum number of raises on each round
103
- numsuits - the number of different suits in the deck
104
- numranks - the number of different ranks in the deck
105
- numholecards - the number of private cards to deal to each player
106
- numboardcards - the number of cards revealed on each round
107
-
108
- Empty lines or lines with '#' as the very first character will be ignored
109
-
110
- If you are creating your own game definitions, please note that game.h defines
111
- some constants for maximums in games (e.g., number of rounds). These may need
112
- to be changed for games outside of the what is being run for the Annual
113
- Computer Poker Competition.
@@ -1,42 +0,0 @@
1
- #############################################################
2
- # Please fill out the following information about your team
3
- #############################################################
4
-
5
- Team Name:
6
- Agent Name (can be the same as team name):
7
-
8
- For each team member, please list the following:
9
- Name, Team leader (y/n)?, e-mail, Academic (y/n, position - e.g., PhD student)?, University/Business affiliation, Location (city, province/state, country)
10
-
11
- Was this submission part of an academic class project? What level of class
12
- (undergraduate/graduate)?
13
-
14
-
15
- ###########################################################################
16
- # Please provide as much information about your agent as possible as the
17
- # competition organizers are very interested in knowing more about the
18
- # techniques used by our competitors.
19
- ###########################################################################
20
-
21
- 1) Is your agent dynamic? That is, does its strategy change throughout the
22
- course of a match, or is the strategy played the same throughout the match?
23
-
24
- 2) Does your agent use a (approximate) Nash equilibrium strategy?
25
-
26
- 3) Does your agent attempt to model your opponents? If so, does it do so
27
- online during the competition or offline from data (e.g., using logs of play or
28
- the benchmark server)?
29
-
30
- 4) Does your agent use techniques that would benefit from additional CPU time
31
- during the competition?
32
-
33
- 5) Does your agent use techniques that would benefit from additional RAM during
34
- the competition?
35
-
36
- 6) Would you agent benefit from additional disk space?
37
-
38
- One/Two Paragraph Summary of Technique
39
-
40
-
41
- References to relevant papers, if any
42
-
@@ -1,101 +0,0 @@
1
- #!/usr/bin/perl
2
-
3
- # Copyright (C) 2011 by the Computer Poker Research Group, University of Alberta
4
-
5
- use Socket;
6
- use File::Basename;
7
-
8
- $hostname = `hostname` or die "could not get hostname";
9
- chomp $hostname;
10
- @hostent = gethostbyname( $hostname );
11
- $#hostent >= 4 or die "could not look up $hostname";
12
- $hostip = inet_ntoa( $hostent[ 4 ] );
13
-
14
- $#ARGV >= 3 or die "usage: play_match.pl matchName gameDefFile #Hands rngSeed player1name player1exe player2name player2exe ... [options]";
15
-
16
- $numPlayers = -1;
17
- open FILE, '<', $ARGV[ 1 ] or die "couldn't open game definition $ARGV[ 1 ]";
18
- while( $_ = <FILE> ) {
19
-
20
- @_ = split;
21
-
22
- if( uc( $_[ 0 ] ) eq 'NUMPLAYERS' ) {
23
- $numPlayers = $_[ $#_ ];
24
- }
25
- }
26
- close FILE;
27
-
28
- $numPlayers > 1 or die "couldn't get number of players from $ARGV[ 1 ]";
29
-
30
-
31
- $#ARGV >= 3 + $numPlayers * 2 or die "too few players on command line";
32
-
33
- pipe STDINREADPIPE, STDINWRITEPIPE or die "couldn't create stdin pipe";
34
- pipe STDOUTREADPIPE, STDOUTWRITEPIPE or die "couldn't create stdout pipe";
35
-
36
- $dealerPID = fork();
37
- if( $dealerPID == 0 ) {
38
- # we're the child
39
-
40
- # replace standard in and standard out with pipe
41
- close STDINWRITEPIPE;
42
- close STDOUTREADPIPE;
43
- open STDIN, '<&STDINREADPIPE' or die "can't dup STDIN";
44
- open STDOUT, '>&STDOUTWRITEPIPE' or die "can't dup STDOUT";
45
- open STDERR, ">>$ARGV[ 0 ].err" or die "can't open log file $ARGV[ 0 ].err";
46
-
47
- @args = ( "dealer", $ARGV[ 0 ], $ARGV[ 1 ],
48
- $ARGV[ 2 ], $ARGV[ 3 ] );
49
-
50
- # add names to the arguments
51
- for( $p = 0; $p < $numPlayers; ++$p ) {
52
- push @args, $ARGV[ 4 + $p * 2 ];
53
- }
54
-
55
- # add any extra arguments (options?) to the arguments
56
- for( $i = 4 + $numPlayers * 2; $i <= $#ARGV; ++$i ) {
57
- push @args, $ARGV[ $i ];
58
- }
59
- exec { "./dealer" } @args or die "Couldn't run dealer";
60
- }
61
-
62
- close STDINREADPIPE;
63
- close STDOUTWRITEPIPE;
64
-
65
- $_ = <STDOUTREADPIPE> or die "couldn't read port description from dealer";
66
- @_ = split;
67
- $#_ + 1 >= $numPlayers or die "couldn't get enough ports from $_";
68
-
69
- for( $p = 0; $p < $numPlayers; ++$p ) {
70
-
71
- $playerPID[ $p ] = fork();
72
-
73
- if( $playerPID[ $p ] == 0 ) {
74
- # we're the child
75
-
76
- # log standard out and standard error
77
- open STDOUT, ">$ARGV[ 0 ].player$p.std"
78
- or die "can't dup player $p STDOUT";
79
- open STDERR, ">$ARGV[ 0 ].player$p.err"
80
- or die "can't dup player $p STDERR";
81
-
82
- ($playerExec, $playerDir) = fileparse( $ARGV[ 4 + $p * 2 + 1 ] );
83
- chdir $playerDir or die "Can't cd to $playerDir: $!\n";
84
- exec { "./$playerExec" } ( "./$playerExec", $hostip, $_[ $p ] )
85
- or die "couldn't run $playerExec from $playerDir for player $p";
86
- }
87
- }
88
-
89
- $_ = <STDOUTREADPIPE>;
90
-
91
- for( $p = 0; $p < $numPlayers; ++$p ) {
92
- waitpid( $playerPID[ $p ], 0 );
93
- }
94
-
95
- waitpid( $dealerPID, 0 );
96
-
97
- $_ or die "couldn't get values from dealer";
98
-
99
- print $_;
100
-
101
- exit( 0 );
@@ -1,238 +0,0 @@
1
- #include <stdlib.h>
2
- #include <stdio.h>
3
- #define __STDC_FORMAT_MACROS
4
- #include <inttypes.h>
5
- #include <assert.h>
6
- #include <string.h>
7
- #include <unistd.h>
8
- #include <netdb.h>
9
- #include <sys/socket.h>
10
- #include <netinet/in.h>
11
- #include <netinet/tcp.h>
12
- #include <sys/wait.h>
13
- #include <errno.h>
14
- #include "net.h"
15
-
16
- #define ARG_SERVERNAME 1
17
- #define ARG_SERVERPORT 2
18
- #define ARG_BOT_COMMAND 7
19
- #define ARG_MIN_ARGS 6
20
-
21
- static void printUsage( FILE *file )
22
- {
23
- fprintf( file, "Sample usages:\n" );
24
- fprintf( file, " bm_run_matches <bm_hostname> <bm_port> <username> <pw> "
25
- "games\n" );
26
- fprintf( file, " See a list of possible opponents\n" );
27
- fprintf( file, " bm_run_matches <bm_hostname> <bm_port> <username> <pw> "
28
- "run 2pl <local script> <# runs> <tag> <seed> <player1> "
29
- "<player2>\n" );
30
- fprintf( file, " Run two-player limit matches\n" );
31
- fprintf( file, " bm_run_matches <bm_hostname> <bm_port> <username> <pw> "
32
- "run 2pn <local script> <# runs> <tag> <seed> <player1> "
33
- "<player2>\n" );
34
- fprintf( file, " Run two-player no-limit matches\n" );
35
- fprintf( file, " bm_run_matches <bm_hostname> <bm_port> <username> <pw> "
36
- "run 3pl <local script> <# runs> <tag> <seed> <player1> <player2> "
37
- "<player3>\n" );
38
- fprintf( file, " Run three-player limit matches\n" );
39
- fprintf( file, " bm_run_matches <bm_hostname> <bm_port> <username> <pw> "
40
- "rerun 2pl <local script> <match index> <tag> <seed> <player1> "
41
- "<player2> (<player3>)\n" );
42
- fprintf( file, " Rerun a match that failed\n" );
43
- fprintf( file, "\n" );
44
- fprintf( file, "<username> is your benchmark server username assigned to "
45
- "you by the competition chair\n" );
46
- fprintf( file, "<pw> is your benchmark server password assigned to you by "
47
- "the competition chair\n" );
48
- fprintf( file, "<local script> is the script that runs your agent locally. "
49
- "It must take a hostname/IP and a port\n" );
50
- fprintf( file, "<num runs> is the number of matches you want to run\n" );
51
- fprintf( file, "<tag> is a name for this set of matches which will appear "
52
- "in the names of the log files\n" );
53
- fprintf( file, "<seed> is a seed used to generate the random seeds that "
54
- "determine the cards in each match\n" );
55
- fprintf( file, "<player-n> is either the name of an opponent or \"local\" "
56
- "for your local agent\n" );
57
- fprintf( file, "\n" );
58
- fprintf( file, "To run N duplicate heads-up matches, do one run of N "
59
- "matches with a given seed, then run a second set of N matches "
60
- "with the same seed but the order of the players reversed\n" );
61
- fprintf( file, "\n" );
62
- fprintf( file, "If one match in a set fails, you can use the \"rerun\" "
63
- "command to rerun the specified match with the specified seed. "
64
- "For example, if you tried to run twenty matches with seed 0 and "
65
- "the last match failed, you could use the \"rerun\" command with "
66
- "seed 0 and match index 19.\n" );
67
- }
68
-
69
- int main( int argc, char **argv )
70
- {
71
- int sock, i;
72
- pid_t childPID;
73
- uint16_t port;
74
- ReadBuf *fromServer;
75
- fd_set readfds;
76
- char line[ READBUF_LEN ];
77
-
78
- if( argc < ARG_MIN_ARGS ) {
79
-
80
- printUsage( stderr );
81
- exit( EXIT_FAILURE );
82
- }
83
-
84
- /* connect to the server */
85
- if( sscanf( argv[ ARG_SERVERPORT ], "%"SCNu16, &port ) < 1 ) {
86
-
87
- fprintf( stderr, "ERROR: invalid port %s\n", argv[ ARG_SERVERPORT ] );
88
- exit( EXIT_FAILURE );
89
- }
90
- sock = connectTo( argv[ ARG_SERVERNAME ], port );
91
- if( sock < 0 ) {
92
-
93
- exit( EXIT_FAILURE );
94
- }
95
-
96
- // EJ additions 9/3/2012
97
- // Turn on keep-alive for socket connection with more frequent checking
98
- // than the Linux default. What I've observed is that if a socket
99
- // connection is idle for long enough it gets dropped. This only
100
- // happens for some users.
101
- int on = 1;
102
- if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) == -1) {
103
- fprintf( stderr, "ERROR: setsockopt failed; errno %i\n", errno );
104
- exit( EXIT_FAILURE );
105
- }
106
- // Not sure what this should be
107
- int num_before_failure = 2;
108
- if (setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &num_before_failure,
109
- sizeof(num_before_failure)) == -1) {
110
- fprintf( stderr, "ERROR: setsockopt failed; errno %i\n", errno );
111
- exit( EXIT_FAILURE );
112
- }
113
- // First check after 60 seconds
114
- int initial_secs = 60;
115
- if (setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &initial_secs,
116
- sizeof(initial_secs)) == -1) {
117
- fprintf( stderr, "ERROR: setsockopt failed; errno %i\n", errno );
118
- exit( EXIT_FAILURE );
119
- }
120
- // Thereafter, also check every 60 seconds
121
- int interval_secs = 60;
122
- if (setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &interval_secs,
123
- sizeof(interval_secs)) == -1) {
124
- fprintf( stderr, "ERROR: setsockopt failed; errno %i\n", errno );
125
- exit( EXIT_FAILURE );
126
- }
127
-
128
- /* set up read buffers */
129
- fromServer = createReadBuf( sock );
130
-
131
- /* write to server */
132
- line[0] = 0;
133
- for( i = 3; i < argc; ++i ) {
134
- strcat( line, argv[i] );
135
- if ( i < argc - 1 ) {
136
- strcat( line, " " );
137
- }
138
- }
139
- strcat( line, "\n" );
140
- int len = strlen(line);
141
- if( write( sock, line, len ) < 0 ) {
142
-
143
- fprintf( stderr, "ERROR: failed while sending to server\n" );
144
- exit( EXIT_FAILURE );
145
- }
146
-
147
- /* main loop */
148
- while( 1 ) {
149
-
150
- /* clean up any children */
151
- while( waitpid( -1, NULL, WNOHANG ) > 0 );
152
-
153
- /* wait for input */
154
- FD_ZERO( &readfds );
155
- FD_SET( sock, &readfds );
156
- i = select( sock + 1, &readfds, NULL, NULL, NULL );
157
- if( i < 0 ) {
158
-
159
- fprintf( stderr, "ERROR: select failed\n" );
160
- exit( EXIT_FAILURE );
161
- }
162
- if( i == 0 ) {
163
- /* nothing ready - shouldn't happen without timeout */
164
-
165
- continue;
166
- }
167
-
168
- /* handle server messages */
169
- if( FD_ISSET( sock, &readfds ) ) {
170
-
171
- /* get the input */
172
- while( ( i = getLine( fromServer, READBUF_LEN, line, 0 ) ) >= 0 ) {
173
-
174
- if( i == 0 ) {
175
-
176
- /* This could be an error or could just signify successful
177
- completion of all matches */
178
- fprintf( stderr, "Server closed connection\n" );
179
- exit( EXIT_SUCCESS );
180
- }
181
-
182
- /* check for server commands */
183
- if( strncasecmp( line, "run ", 4 ) == 0 ) {
184
-
185
- /* split the rest of the line into name ' ' port */
186
- for( i = 4; line[ i ]; ++i ) {
187
-
188
- if( line[ i ] == ' ' ) {
189
- /* found the separator */
190
-
191
- line[ i ] = 0;
192
- break;
193
- }
194
- }
195
-
196
- printf( "starting match %s:%s", &line[ 4 ], &line[ i + 1 ] );
197
- fflush( stdout );
198
-
199
- /* run `command machine port` */
200
- childPID = fork();
201
- if( childPID < 0 ) {
202
-
203
- fprintf( stderr, "ERROR: fork() failed\n" );
204
- exit( EXIT_FAILURE );
205
- }
206
- if( childPID == 0 ) {
207
- /* child runs the command */
208
-
209
- execl( argv[ ARG_BOT_COMMAND ],
210
- argv[ ARG_BOT_COMMAND ],
211
- &line[ 4 ],
212
- &line[ i + 1 ],
213
- NULL );
214
- fprintf( stderr,
215
- "ERROR: could not run %s\n",
216
- argv[ ARG_BOT_COMMAND ] );
217
- exit( EXIT_FAILURE );
218
- }
219
- } else {
220
- /* just a message, print it out */
221
-
222
- if( fwrite( line, 1, i, stdout ) < 0 ) {
223
-
224
- fprintf( stderr, "ERROR: failed while printing server message\n" );
225
- exit( EXIT_FAILURE );
226
- }
227
- fflush( stdout );
228
-
229
- if( ! strcmp( line, "Matches finished\n") ) {
230
- exit( EXIT_SUCCESS );
231
- }
232
- }
233
- }
234
- }
235
- }
236
-
237
- return EXIT_SUCCESS;
238
- }