Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.89 KB | None | 0 0
  1.   def computerVsComputer (board: Array[Int], depth: Int): Unit = {
  2.  
  3.     var p1 = new RandomPlayer("");
  4.     var p2 = new RandomPlayer("");
  5.  
  6.     var winners = List[Int]();
  7.     var n = 0;
  8.  
  9.     println("How many games would you like to play?")
  10.     try {
  11.       n = StdIn.readInt();
  12.     } catch {
  13.       case e: NumberFormatException => println("Error: " + e)
  14.     }
  15.  
  16.     for (i <- 0 until n) {
  17.       winners = winners :+ play(p1, p2, board, depth, false);
  18.       for (j <- 0 to board.size - 1) {
  19.         board(j) = 0;
  20.       }
  21.     }
  22.  
  23.       print("P(x vinner) = ")
  24.       val pWin1 = winners.count(_ == 1).toDouble / n.toDouble;
  25.       println(pWin1);
  26.  
  27.       print("P(o vinner) = ");
  28.       val pWin2 = winners.count(_ == -1).toDouble / n.toDouble;
  29.       println(pWin2);
  30.  
  31.       print("P(lika) = ");
  32.       val pWin3 = winners.count(_ == 0).toDouble / n.toDouble;
  33.       println(pWin3);
  34.  
  35.  
  36.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement