public bool UpdatePosition(Move move) { // Update terrain Pons from = Board[move.from.y, move.from.x]; Pons to = Board[move.to.y, move.to.x]; Console.WriteLine("{0}:{1} -> {1}:{2}", move.from.y, move.from.x, move.to.y, move.to.x); // Check if the move is legal if (rules(from, to, move)) { // Copy the piece and erase the previous one Board[move.to.y, move.to.x] = Board[move.from.y, move.from.x]; Board[move.from.y, move.from.x] = new Pons(); } else { Console.WriteLine("Illegal Move!"); Console.ReadKey(); return(false); } return(true); }
public bool rules(Pons PONS_FROM, Pons PONS_TO, Move move) { // Régle numéro 1: IT'S MY TURN! // Si le tour, modulo 2 == 0 blanc, n'est pas 1 == blanc alors zouh if ((Program.Turn % 2 == 0 && PONS_FROM.player != 1) || (Program.Turn % 2 != 0 && PONS_FROM.player == 1)) { return(false); } // Régle numéro 2: Friendly Fire! if (!(PONS_TO.player != PONS_FROM.player)) { return(false); } // Régle numéro 2: YOU CAN'T DO THAT DUDE // Vérifie si la destination est accesible par la pièce, et leurs comportement // Autorise les pieces suivantes switch (PONS_FROM.unit_) { // Roi case "O": // Can only move 1 ahead and can't eat friendly piece if ((move.from.x + 1 >= move.to.x) || (move.from.y + 1 >= move.to.y)) { return(true); } break; // Reine case "Q": return(true); break; // Pion case "P": // Can only go forward if (move.from.x != move.to.x) { return(false); } // Trying a first move when already one happend if (move.from.x + 2 <= move.to.x && PONS_FROM.first_move == false) { return(false); } Console.WriteLine(move.from.y + ":" + move.to.y); if (move.from.y - move.to.y < 1) { return(true); } // Signale le premier mouvement, pas besoin de if, opération inutile. PONS_FROM.first_move = true; break; default: return(false); } return(true); }