Beispiel #1
0
        public int makeMove(int r, int q)
        {
            int win      = -1;
            int rChecker = r + fieldRadius;
            int qChecker = q + fieldRadius;

            //Radius check
            if (rChecker >= 20 || qChecker >= 20 || rChecker <= -1 || qChecker <= -1)
            {
                return(win);
            }

            if (myField[r + fieldRadius, q + fieldRadius] != 3 && myField[r + fieldRadius, q + fieldRadius] != 4)
            {
                //Invalid move! -> not playable
                return(win);
            }
            else
            {
                if (black)
                {
                    myField[r + fieldRadius, q + fieldRadius] = 1;
                    Console.WriteLine("SET POS: " + (r + fieldRadius) + " ; " + (q + fieldRadius) + " set to black");
                }
                else
                {
                    myField[r + fieldRadius, q + fieldRadius] = 2;
                    Console.WriteLine("SET POS: " + (r + fieldRadius) + " ; " + (q + fieldRadius) + " set to red");
                }

                //remove last recommendation
                removeMoves(4);

                //Check the field for possible moves
                myField = checkPosMoves(myField);

                CheckWin check = new CheckWin(this);

                //Check for winner
                win = check.checkWin(myField);

                //Next players turn!
                black = !black;

                if (win == 1 || win == 2)
                {
                    removeMoves(3);
                }

                //Make a deep copy
                int[,] bufferField = myField.Clone() as int[, ];

                //add move to moveList
                moveList.Add(bufferField);
                moveCounter++;

                return(win);
            }
        }
Beispiel #2
0
 public AI(Map bufferMap)
 {
     map   = bufferMap;
     check = new CheckWin(map);
 }