Advertisement
Guest User

asdasdads

a guest
Nov 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #!/bin/bash
  2. # Script for running two othello programs agianst eachother
  3. # Usage: othellostart white_player black_player time_limit
  4. # The time limit is in seconds
  5. # Author: Henrik Björklund
  6. # Edited by Ola Ringdahl
  7.  
  8. if [ $# -lt 3 ]; then
  9. echo "Too few arguments."
  10. echo "Usage: othellostart white_player black_player time_limit"
  11. exit 1
  12. fi
  13.  
  14. pos="WEEEEEEEEEEEEEEEEEEEEEEEEEEEOXEEEEEEXOEEEEEEEEEEEEEEEEEEEEEEEEEEE"
  15.  
  16. white="$1" # the program playing white
  17. black="$2" # the program playing black
  18. time="$3" # timelimit
  19. endgame="no"
  20. whitepass="no"
  21. blackpass="no"
  22. tomove="black"
  23. nMoves=0
  24. whiteTmax=0
  25. blackTmax=0
  26. whiteTtot=0
  27. blackTtot=0
  28.  
  29. declare -a moves
  30. index=0;
  31.  
  32. # Play a full game
  33. while [ "$endgame" != "yes" ]
  34. do
  35. STARTTIME=$(date +%s)
  36. move=`$white $pos $time 0`
  37. ENDTIME=$(date +%s)
  38.  
  39. moves[index]="$move"
  40. let "index += 1"
  41.  
  42. pos=`java Mover "$pos" "$move"`
  43. if [ "$move" == "pass" ]
  44. then
  45. whitepass="yes"
  46. if [ "$blackpass" == "yes" ]
  47. then
  48. endgame="yes"
  49. fi
  50. else
  51. whitepass="no"
  52. fi
  53. whiteT=$(($ENDTIME - $STARTTIME))
  54. whiteTtot=$(($whiteTtot + $whiteT))
  55. if [ "$whiteT" -gt "$whiteTmax" ]
  56. then
  57. whiteTmax=$whiteT
  58. fi
  59.  
  60. if [ "$endgame" != "yes" ]
  61. then
  62. STARTTIME=$(date +%s)
  63. move=`$black $pos $time 0`
  64. ENDTIME=$(date +%s)
  65.  
  66. moves[index]="$move"
  67. let "index += 1"
  68.  
  69. pos=`java Mover "$pos" "$move"`
  70. if [ "$move" == "pass" ]
  71. then
  72. blackpass="yes"
  73. if [ "$whitepass" == "yes" ]
  74. then
  75. endgame="yes"
  76. fi
  77. else
  78. blackpass="no"
  79. fi
  80. blackT=$(($ENDTIME - $STARTTIME))
  81. blackTtot=$(($blackTtot + $blackT))
  82. if [ "$blackT" -gt "$blackTmax" ]
  83. then
  84. blackTmax=$blackT
  85. fi
  86. fi
  87.  
  88. nMoves=$(($nMoves+1))
  89. done
  90.  
  91. whitecount=`java Counter "$pos"`
  92. if [ $whitecount -gt 0 ]
  93. then
  94. winner="White"
  95. else
  96. winner="Black"
  97. whitecount=$((-1 * $whitecount))
  98. fi
  99.  
  100. whiteTmean=$(awk "BEGIN {printf \"%.1f\", ${whiteTtot} / ${nMoves}}")
  101. blackTmean=$(awk "BEGIN {printf \"%.1f\", ${blackTtot} / ${nMoves}}")
  102.  
  103. echo "***************************************"
  104. echo "Results for $white vs. $black:"
  105. echo "$winner won with $whitecount points"
  106. echo "Average time for white: $whiteTmean s (max: $whiteTmax s)"
  107. echo "Average time for black: $blackTmean s (max: $blackTmax s)"
  108. echo "Time Limit: $time s"
  109. echo "Number of Moves: $nMoves"
  110. # echo ${moves[@]}
  111. echo "***************************************"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement