public void CreatePowns() { //Role 0=pawn/1=rook/2=knight/3=bishop/king=4/queen=5 //creat pawn white for (int i = 1; i <= 8; i++) { Pown pawn = new Pown(0, "white", i, 7, "pawnWhite" + i.ToString()); Pawns.Add(pawn); } //creat pawn black for (int i = 1; i <= 8; i++) { Pown pawn = new Pown(0, "black", i, 2, "pawnBlack" + i.ToString()); Pawns.Add(pawn); } Pown rook1B = new Pown(1, "black", 1, 1, "rookBlack1"); Pawns.Add(rook1B); Pown rook2B = new Pown(1, "black", 8, 1, "rookBlack2"); Pawns.Add(rook2B); Pown knight1B = new Pown(2, "black", 2, 1, "knightBlack1"); Pawns.Add(knight1B); Pown knight2B = new Pown(2, "black", 7, 1, "knightBlack2"); Pawns.Add(knight2B); Pown bishop1B = new Pown(3, "black", 3, 1, "bishopBlack1"); Pawns.Add(bishop1B); Pown bishop2B = new Pown(3, "black", 6, 1, "bishopBlack2"); Pawns.Add(bishop2B); Pown kingB = new Pown(4, "black", 5, 1, "kingBlack"); Pawns.Add(kingB); Pown queenB = new Pown(5, "black", 4, 1, "queenBlack"); Pawns.Add(queenB); //change color Pown rook1W = new Pown(1, "white", 1, 8, "rookWhite1"); Pawns.Add(rook1W); Pown rook2W = new Pown(1, "white", 8, 8, "rookWhite2"); Pawns.Add(rook2W); Pown knight1W = new Pown(2, "white", 2, 8, "knightWhite1"); Pawns.Add(knight1W); Pown knight2W = new Pown(2, "white", 7, 8, "knightWhite2"); Pawns.Add(knight2W); Pown bishop1W = new Pown(3, "white", 3, 8, "bishopWhite1"); Pawns.Add(bishop1W); Pown bishop2W = new Pown(3, "white", 6, 8, "bishopWhite2"); Pawns.Add(bishop2W); Pown kingW = new Pown(4, "white", 5, 8, "kingWhite"); Pawns.Add(kingW); Pown queenW = new Pown(5, "white", 4, 8, "queenWhite"); Pawns.Add(queenW); }
public void Castling(string source, string second) { //set rook and king and verificate movement for castling Pown king = new Pown(); Pown rook = new Pown(); PositionsBag bag = new PositionsBag(); Boolean castling = false; foreach (Pown item in Pawns) { if (item.Name == source) { if (item.Role == 1) { rook = item; } else { king = item; } } if (item.Name == second) { if (item.Role == 1) { rook = item; } else { king = item; } } } if (king.CountMove == 0 && rook.CountMove == 0) { bag = PossibleMovementOfRook(rook.PosX, rook.PosY, GetAllPosOfPawns()); for (int i = 0; i < bag.XList.Count; i++) { if (king.PosX == bag.XList[i] && king.PosY == bag.YList[i]) { castling = true; } } } if (castling == true) { if (rook.PosX == 1) { king.PosX = king.PosX - 2; rook.PosX = rook.PosX + 3; } else { king.PosX = king.PosX + 2; rook.PosX = rook.PosX - 2; } } ChangePos(king.Name, king.PosX, king.PosY); ChangePos(rook.Name, king.PosX, king.PosY); }
private PositionsBag PossibleMovementOfPawn(Pown item, int x, int y, List <List <int> > mainList) { PositionsBag bag = new PositionsBag(); List <int> xList = new List <int>(); List <int> yList = new List <int>(); bool moveDiagonalToken = true; bool twoMoveToken = true; for (int i = 0; i < mainList[0].Count; i++) { if (item.Color == "black") { //check if a pown was in diagonal if (mainList[0][i] == (item.PosX + 1) && (item.PosY + 1) == mainList[1][i]) { xList.Add(x + 1); yList.Add(y + 1); } if (mainList[0][i] == (item.PosX - 1) && (item.PosY + 1) == mainList[1][i]) { xList.Add(x - 1); yList.Add(y + 1); } //check if a pown was in front if (mainList[1][i] == (item.PosY + 1) && mainList[0][i] == item.PosX) { moveDiagonalToken = false; } if (mainList[1][i] == (item.PosY + 1) && mainList[0][i] == item.PosX) { moveDiagonalToken = false; } if (mainList[1][i] == (item.PosY + 2) && mainList[0][i] == item.PosX) { twoMoveToken = false; } if (moveDiagonalToken == true && mainList[0].Count - 1 == i) { xList.Add(x); yList.Add(y + 1); } // for two case movement if (item.CountMove == 0 && twoMoveToken == true) { xList.Add(x); yList.Add(y + 2); } } else { //check if a pown was in diagonal if (mainList[0][i] == (item.PosX + 1) && (item.PosY - 1) == mainList[1][i]) { xList.Add(x + 1); yList.Add(y - 1); } if (mainList[0][i] == (item.PosX - 1) && (item.PosY - 1) == mainList[1][i]) { xList.Add(x - 1); yList.Add(y - 1); } //check if a pown was in front if (mainList[1][i] == (item.PosY - 1) && mainList[0][i] == item.PosX) { moveDiagonalToken = false; } if (mainList[1][i] == (item.PosY - 2) && mainList[0][i] == item.PosX) { twoMoveToken = false; } if (moveDiagonalToken == true && mainList[0].Count - 1 == i) { xList.Add(x); yList.Add(y - 1); } // for two case movement if (item.CountMove == 0 && twoMoveToken == true) { xList.Add(x); yList.Add(y - 2); } } } bag.XList = xList; bag.YList = yList; return(bag); }