Exemplo n.º 1
0
        public static bool handleMovementInput(String input)
        {
            string[] answer;
            answer = input.Split(" ");
            if (answer.Length < 4)
            {
                Console.WriteLine("Movimento em formato incorreto, tente novamente no formato x1 y1 x2 y2\n");
                return(true);
            }
            int[] coordinates = new int[4];
            try{
                for (int i = 0; i < answer.Length; i++)
                {
                    coordinates[i] = Int32.Parse(answer[i]) - 1;
                }
            }catch (System.FormatException) {
                Console.WriteLine("Movimento em formato incorreto, tente digitar apenas números separados por espaços\n");
            }

            if (!RuleMachine.validateMove(coordinates, currentState.board, currentState.currentPlayer))
            {
                return(true);
            }

            movePiece(coordinates);
            return(false);
        }
Exemplo n.º 2
0
        public int max_value(State state, int alfa, int beta)
        {
            if (cut(state) || state.gameIsOver())
            {
                return(eval(state));
            }

            int v = Int32.MinValue;
            int temp;
            LinkedList <int[]> moves = RuleMachine.possible_moves(state);

            foreach (var move in moves)
            {
                //MAX(v,min_value(result(s,a),alfa,beta))
                temp = min_value(State.result(state, move), alfa, beta);
                if (v < temp)
                {
                    v = temp;
                }

                if (v >= beta)
                {
                    return(v);
                }

                //MAX(alfa,v)
                if (alfa < v)
                {
                    alfa = v;
                }
            }
            return(v);
        }
Exemplo n.º 3
0
        public static State result(State oldState, int[] action)
        {
            State newState = new State(oldState.board, oldState.currentPlayer, oldState.lastMove, oldState.playsCount, oldState.playsWithoutCapture);

            if (RuleMachine.isAttackMove(action, newState.board))
            {
                newState.playsWithoutCapture = 0;
            }
            else
            {
                newState.playsWithoutCapture++;
            }

            char piece = newState.board[action[0], action[1]];

            newState.board[action[0], action[1]] = Types.EMPTY;
            newState.board[action[2], action[3]] = piece;
            newState.currentPlayer = newState.currentPlayer == 1 ? 2 : 1;
            newState.lastMove      = action;
            newState.playsCount++;

            newState.registerGameIsOver();

            return(newState);
        }
Exemplo n.º 4
0
        public static void movePiece(int[] coordinates)
        {
            if (RuleMachine.isAttackMove(coordinates, currentState.board))
            {
                capture(coordinates, currentState.board);
            }

            currentState = State.result(currentState, coordinates);
        }
Exemplo n.º 5
0
        public int[] alpha_beta_search(State state)
        {
            int v    = Int32.MinValue;
            int alfa = Int32.MinValue;
            int beta = Int32.MaxValue;

            LinkedList <int[]> moves = RuleMachine.possible_moves(state);
            int i = 0, temp, moveIndex = 0;

            foreach (var move in moves)
            {
                //MAX(v,min_value(result(s,a),alfa,beta))
                temp = min_value(State.result(state, move), alfa, beta);
                if (v < temp)
                {
                    v         = temp;
                    moveIndex = i;
                }

                if (v >= beta)
                {
                    return(move);
                }

                //MAX(alfa,v)
                if (alfa < v)
                {
                    alfa = v;
                }

                i++;
            }

            LinkedList <int[]> .Enumerator e = moves.GetEnumerator();
            for (i = 0; i < moveIndex + 1; i++)
            {
                e.MoveNext();
            }
            return(e.Current);
        }
Exemplo n.º 6
0
        //função de avaliação sobre a quantidade de movimentos possiveis
        //retorna a qtd de movimentos possiveis
        public static int evalMobility(State state)
        {
            LinkedList <int[]> moves = RuleMachine.possible_moves(state);

            return(moves.Count);
        }