Ejemplo n.º 1
0
        public string StartSimulations(Board board, int numberOfSimulations)
        {
            Random random = new Random();
            List <MonteCarloMove> moves = new List <MonteCarloMove>();
            MonteCarloMove        move  = new MonteCarloMove();

            AddMoves(moves, board);
            int amountOfTestedMoves = moves.Count;

            TestMoves(numberOfSimulations, board, moves, amountOfTestedMoves);
            setResult(moves);
            moves.Sort((s2, s1) => s1.result.CompareTo(s2.result));

            int bestOf = 3;

            if (moves.Count < 3)
            {
                bestOf = moves.Count;
            }
            TestMoves(numberOfSimulations, board, moves, bestOf);
            setResult(moves);
            for (int i = bestOf; i < moves.Count; i++)
            {
                moves[i].result = 0;
            }
            moves.Sort((s2, s1) => s1.result.CompareTo(s2.result));
            Console.WriteLine("Ruch: " + moves[0].MoveCode + " Liczba prob: " + moves[0].trys + " liczba wygranych: " + moves[0].wins + " Szansa na wygrana " + moves[0].result);
            //  writeToFile(bestOf, moves);
            return(moves[0].MoveCode);
        }
Ejemplo n.º 2
0
 public void AddMoves(List <MonteCarloMove> moves, Board board)
 {
     foreach (MonteCarloMove.PossibleMoves code in Enum.GetValues(typeof(MonteCarloMove.PossibleMoves)))
     {
         MonteCarloMove move     = new MonteCarloMove();
         string         moveCode = code.ToString();
         move = new MonteCarloMove(moveCode);
         if (Move.IsMovePossible(move, this, board.CoinsOnBoard, board.MinesOnBoard))
         {
             moves.Add(new MonteCarloMove(moveCode));
         }
     }
     DeleteNone(moves);
 }