Skip to content

Instantly share code, notes, and snippets.

@dkuebric
Created July 30, 2014 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkuebric/df96af8420f268037fe3 to your computer and use it in GitHub Desktop.
Save dkuebric/df96af8420f268037fe3 to your computer and use it in GitHub Desktop.
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 12 13 7 7 5 13 9 11 16 7
2 team2 9998 0 1 19996 9 16 11 16 7 8 13 2 7 11
3 team3 9997 0 2 19994 17 10 12 13 6 9 9 5 8 11
4 team4 9996 0 3 19992 11 9 8 13 10 8 8 13 8 12
real 0m3.111s
user 0m3.117s
sys 0m0.011s
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 6 8 12 9 16 7 11 13 7 11
2 team2 9998 0 1 19996 12 7 11 11 9 12 14 10 6 8
3 team3 9997 0 2 19994 10 10 9 12 6 12 11 13 7 10
4 team4 9996 0 3 19992 11 14 6 13 6 15 7 9 8 11
real 0m3.123s
user 0m3.128s
sys 0m0.010s
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 11 11 10 6 9 10 8 12 8 15
2 team2 9998 0 1 19996 8 7 8 13 11 10 11 10 8 14
3 team3 9997 0 2 19994 11 16 9 5 5 10 9 11 12 12
4 team4 9996 0 3 19992 12 6 7 9 14 6 13 14 10 9
real 0m3.124s
user 0m3.128s
sys 0m0.009s
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 11 10 15 9 7 8 13 6 9 12
2 team2 9998 0 1 19996 14 11 13 5 8 11 17 6 7 8
3 team3 9997 0 2 19994 8 7 7 7 13 11 6 17 15 9
4 team4 9996 0 3 19992 15 9 10 7 5 9 7 17 13 8
real 0m3.126s
user 0m3.133s
sys 0m0.011s
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 15 8 10 6 13 8 9 15 9 7
2 team2 9998 0 1 19996 9 8 10 15 8 9 13 11 9 8
3 team3 9997 0 2 19994 9 10 13 12 7 10 11 7 11 10
4 team4 9996 0 3 19992 5 7 10 10 9 7 14 9 15 14
real 0m3.119s
user 0m3.121s
sys 0m0.010s
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 14 9 11 9 9 7 13 10 12 6
2 team2 9998 0 1 19996 9 10 11 8 6 14 9 11 9 13
3 team3 9997 0 2 19994 7 11 10 6 14 15 12 7 13 5
4 team4 9996 0 3 19992 14 6 9 6 15 11 10 9 12 8
real 0m3.126s
user 0m3.133s
sys 0m0.009s
dan@ponderous:~/code/blotto $ time ./genteam 10 100 10000 | ./blotto 10 100 | head -n 5
Pos Name W D L Pts Soldiers
1 team1 9999 0 0 19998 11 10 12 6 11 8 6 14 10 12
2 team2 9998 0 1 19996 13 14 8 5 10 9 10 11 12 8
3 team3 9997 0 2 19994 12 10 7 10 7 9 8 16 10 11
4 team4 9996 0 3 19992 6 16 11 16 11 8 7 5 11 9
real 0m3.094s
user 0m3.102s
sys 0m0.009s
dan@ponderous:~/code/blotto $ git diff
diff --git a/blotto.c b/blotto.c
index e900988..64e84ef 100644
--- a/blotto.c
+++ b/blotto.c
@@ -196,8 +196,19 @@ int main(int argc, char **argv) {
/* fight! */
for(i = 0; i < battlefields; i++) {
- if(player[p1].soldiers[i] > player[p2].soldiers[i]) score++;
- else if(player[p1].soldiers[i] < player[p2].soldiers[i]) score--;
+ int left = player[p1].soldiers[i];
+ int right = player[p2].soldiers[i];
+ if (i > 0) {
+ left += player[p1].soldiers[i-1]/2;
+ right += player[p2].soldiers[i-1]/2;
+ }
+ if (left > right) {
+ score++;
+ } else if (right < left) {
+ score--;
+ } else {
+ /* no penalty */
+ }
}
/* administer points */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment