Example #1
0
        private bool Check_Move_handled(string smove, int player)               //DONT CALL WITHOUT THE HANDLER, Check_Move
        {
            //check move syntax
            //Check if move string is of valid format
            if (!drawing.check_Syntax(smove))
            {
                return(false);
            }
            List <Piece> move = Split(smove);

            //every position in list on a black field?
            foreach (Piece position in move)
            {
                if (!is_black(position))
                {
                    return(false);
                }
            }   //moves which made it this far are syntacticly correct, next check if they comply by the rules
            //check if its moving an own piece ( -20 converts lowercase to uppercase)
            if (!(board[move[0]] == color(player) || board[move[0]] == Convert.ToChar(color(player) - 32)))
            {
                MessageBox.Show("Du musst deinen eigenen Stein bewegen :)");
                return(false);
            }
            //target must be empty
            if (board[move[1]] != '.')
            {
                MessageBox.Show("Das Zielfeld ist bereits besetzt.");
                return(false);
            }
            //move is a normal move
            if (!is_jump(move[0], move[1]))
            {
                //moves are always 5 chars long
                if (smove.Length != 5)
                {
                    return(false);
                }
                foreach (KeyValuePair <Piece, char> kvp in board)
                {
                    if (!(kvp.Value == color(player) || kvp.Value == (color(player) - 32)))
                    {
                        continue;
                    }
                    //if a jump is possible, the move should have been a jump
                    if (possible_jumps(kvp.Key, player).Count != 0)
                    {
                        MessageBox.Show("Du musst Springen!");
                        return(false);
                    }
                }
                //there is no valid jump, is the move valid?
                if (is_move(move[0], move[1]))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }   //move is a jump
            //check if every jump until the last one is valid
            int i = 0;

            while (i < (move.Count - 1))
            {
                //is the jump valid?
                if (!possible_jumps(move[i], player).Contains(move[i + 1]))
                {
                    return(false);
                }
                //perform jump
                board[move[i + 1]] = board[move[i]];
                board[move[i]]     = '.';
                board[between(move[i], move[i + 1])] = '.';
                i++;
            }
            //if the player can still jump it is invalid (player has to jump as far as his current chain allows)
            if (possible_jumps(move[i], player).Count != 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }