public JsonResult moveControl(moveC move) { var piece = (from pc in listPieces.pieces where pc.id == move.id select pc).FirstOrDefault(); string result = "", Direction = ""; Direction = (piece.row == move.row || piece.col == move.col) ? "direct" : "cross"; switch (piece.name) { case "pawn": // { int stepSize = piece.isStart == true ? 1 : 2; //ilk hareketinde 2 tane adım atabilir Boolean backControl = piece.color == piece.getColor.black ? (piece.row - move.row > 0 ? false : true) : (piece.row - move.row < 0 ? false : true); //geriye gidebilirmi? result = backControl == true?OControl(move, piece, stepSize, Direction) : "false;"; //geriye gidebilirmi? break; } case "rook": //sadece x-y ekseninde hareket edebilir { result = OControl(move, piece, null, "direct"); break; } case "knight": //L iki ileri-geri bir sağa-sola hareket edebilir { result = OControl(move, piece, null, "L"); break; } case "bishop": //sadece çapraz hareket edebilir { result = OControl(move, piece, null, "cross"); break; } case "queen": //her yöne hareket edebilir { result = OControl(move, piece, null, Direction); break; } case "king": //heryöne hareket edebilir { result = OControl(move, piece, 1, Direction); break; } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public properties getEatenPiece(properties piece, moveC move) { //Going to top. if (move.row < piece.row) { //If Diagonal to the right do.. else... return(move.col > piece.col ? getPiece(move.row + 1, move.col - 1):getPiece(move.row + 1, move.col + 1)); } //Going to bottom. else { //If Diagonal to the right do.. else.. return(move.col > piece.col ? getPiece(move.row - 1, move.col - 1) : getPiece(move.row - 1, move.col + 1)); } }
public JsonResult moveControl(moveC move) { var piece = (from pc in board.pieces where pc.id == move.id select pc).FirstOrDefault(); string result = "", Direction = ""; Direction = (piece.row == move.row || piece.col == move.col) ? "direct" : "cross"; switch (piece.name) { case "pawn": { int stepSize = piece.isStart == true ? 1 : 2; Boolean backControl = piece.color == piece.getColor.black ? (piece.row - move.row > 0 ? false : true) : (piece.row - move.row < 0 ? false : true); result = backControl == true?OControl(move, piece, stepSize, Direction) : "false;"; // break; } case "crown": { int stepSize = piece.isStart == true ? 1 : 2; Boolean backControl = piece.color == piece.getColor.black ? (piece.row - move.row > 0 ? false : true) : (piece.row - move.row < 0 ? false : true); result = true ? OControl(move, piece, stepSize, "crown") : "false"; break; } } if (board.isFinished()) { if (board.currentColorTurn == "White") { board.redPlayerScore++; } else { board.bluePlayerScore++; } result += ";" + board.redPlayerScore + "|" + board.bluePlayerScore; } else { result += ";"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public String OControl(moveC move, properties piece, Int32?stepSize, String Direction) { board.currentColorTurn = piece.color; //No es bajo acoplamiento. String removeID = ""; String crownID = ""; Boolean legitMove = false; bool SelectedCellEmpty = board.emptyCell(move.row, move.col); bool jumpAvailable = board.hasJump(); int rowStepSize = Math.Abs(piece.row - move.row); int colStepSize = Math.Abs(piece.col - move.col); switch (Direction) { case "cross": { if (SelectedCellEmpty) { if (jumpAvailable) { //Try to eat. if (rowStepSize == 2 || colStepSize == 2) { properties pieceToEat = board.getEatenPiece(piece, move); if ((pieceToEat.color != board.currentColorTurn) && pieceToEat.color != "Blank") { removeID = pieceToEat.id; board.removePiece(removeID); legitMove = true; } } } else if (rowStepSize == 1 && colStepSize == 1) { legitMove = true; } } if (((move.row == 1 || move.row == 8) && piece.name == "pawn")) { piece.col = move.col; piece.row = move.row; piece.name = "crown"; board.removePiece(piece.id); board.pieces.Add(piece); crownID = piece.id; } break; } case "crown": { if (SelectedCellEmpty) { if (jumpAvailable) { //Try to eat. if (rowStepSize == 2 || colStepSize == 2) { properties pieceToEat = board.getEatenPiece(piece, move); if ((pieceToEat.color != board.currentColorTurn) && pieceToEat.color != "Blank") { removeID = pieceToEat.id; board.removePiece(removeID); legitMove = true; } } } else { legitMove = true; } } break; } } if (legitMove) { board.removePiece(piece.id); piece.col = move.col; piece.row = move.row; if (piece.name == "crown") { piece.name = "crown"; } board.pieces.Add(piece); board.bot = true; } return(legitMove + ";" + removeID + ";" + crownID); }
public String OControl(moveC move, properties piece, Int32?stepSize, String Direction) { String removeID = ""; //silinecek taşın id si Boolean isMoveable = false; //taş hareket edebilirmi List <cor> se = new List <cor>(); List <properties> ps = new List <properties>(); var item = new cor(); int x = piece.row; int y = piece.col; switch (Direction) { case "direct": { if (piece.row != move.row && piece.col != move.col) { break; } if (stepSize == null) //adım sayısı null ise sınır yoktur { stepSize = Math.Abs(move.col - piece.col) != 0 ? Math.Abs(move.col - piece.col) : Math.Abs(move.row - piece.row); } else { if (Math.Abs(piece.row - move.row) == stepSize || Math.Abs(piece.row - move.row) == 1) //adım sayısı belirtilir { stepSize = Math.Abs(piece.row - move.row); } else if (Math.Abs(piece.col - move.col) == stepSize || Math.Abs(piece.col - move.col) == 1) { stepSize = Math.Abs(piece.col - move.col); } else { break; } } for (int i = 1; i <= stepSize; i++) //hareket ettiği ekseni bul { if (move.row >= piece.row && x + i <= 8 && piece.col == move.col) //x+ { se.Add(new cor() { col = y, row = x + i }); } if (move.row < piece.row && x - i >= 1 && piece.col == move.col) //x- { se.Add(new cor() { col = y, row = x - i }); } if (move.col >= piece.col && y + i <= 8 && piece.row == move.row) //y+ { se.Add(new cor() { col = y + i, row = x }); } if (move.col <= piece.col && y - i >= 1 && piece.row == move.row) //y- { se.Add(new cor() { col = y - i, row = x }); } } break; } case "cross": { if (piece.row == move.row || piece.col == move.col) { break; } if (stepSize == null) { stepSize = Math.Abs(move.col - piece.col); } else { if (Math.Abs(piece.row - move.row) != 1 || Math.Abs(piece.col - move.col) != 1) { break; } } for (int i = 1; i <= stepSize; i++) { if (move.row > piece.row && move.col > piece.col && x + i <= 8 && y + i <= 8) //x+ y+ { se.Add(new cor() { col = y + i, row = x + i }); } if (move.row < piece.row && move.col < piece.col && x - i >= 1 && y - i >= 1) //x- y- { se.Add(new cor() { col = y - i, row = x - i }); } if (move.row > piece.row && move.col < piece.col && x + i <= 8 && y - i >= 1) //x+ y- { se.Add(new cor() { col = y - i, row = x + i }); } if (move.row < piece.row && move.col > piece.col && x - i >= 1 && y + i <= 8) //x- y+ { se.Add(new cor() { col = y + i, row = x - i }); } } break; } case "L": { if (move.col == y + 1 && move.row == x + 2 && x + 2 <= 8 && y + 1 <= 8) //y+1 x+2 { se.Add(new cor() { col = y + 1, row = x + 2 }); } if (move.col == y + 1 && move.row == x - 2 && x - 2 >= 1 && y + 1 <= 8) //y+1 x-2 { se.Add(new cor() { col = y + 1, row = x - 2 }); } if (move.col == y + 2 && move.row == x + 1 && x + 1 <= 8 && y + 2 <= 8) //y+2 x+1 { se.Add(new cor() { col = y + 2, row = x + 1 }); } if (move.col == y + 2 && move.row == x - 1 && x - 1 >= 1 && y + 2 <= 8) //y+2 x-1 { se.Add(new cor() { col = y + 2, row = x - 1 }); } if (move.col == y - 1 && move.row == x + 2 && x + 2 <= 8 && y - 1 >= 1) //y-1 x+2 { se.Add(new cor() { col = y - 1, row = x + 2 }); } if (move.col == y - 1 && move.row == x - 2 && x - 2 >= 1 && y - 1 >= 1) //y-1 x-2 { se.Add(new cor() { col = y - 1, row = x - 2 }); } if (move.col == y - 2 && move.row == x + 1 && x + 1 <= 8 && y - 2 <= 8) //y-2 x+1 { se.Add(new cor() { col = y - 2, row = x + 1 }); } if (move.col == y - 2 && move.row == x - 1 && x - 1 >= 1 && y - 2 <= 8) //y-2 x-1 { se.Add(new cor() { col = y - 2, row = x - 1 }); } break; } default: break; } foreach (var direct in se)//hareket ettiği eksende hangi taşlar var { foreach (var pc in listPieces.pieces) { if (direct.row == pc.row && direct.col == pc.col) { ps.Add(pc); } } } if (se.Count > 0) { if (ps.Count == 0)//önünde taş yoksa hareket edebilir { if (Direction == "cross" && piece.name == piece.getName.pawn) { } else { isMoveable = true; } } if (ps.Count == 1 && ps[0].color != piece.color)//önünde karşı takımın taşı varsa yenebilirmi { if (Direction == "direct" && piece.name == piece.getName.pawn) { } else { listPieces.pieces.RemoveAll(a => a.id == ps[0].id); //listeden yenen elemanı çıkartıyoruz removeID = ps[0].id; //client tarafta silinecek olan taşın id sini gönderiyoruz isMoveable = true; } } if (isMoveable == true) //hareket kabul edildiyse { piece.col = move.col; //kalenin yeni sutun değerini güncelle piece.row = move.row; //kalenin yeni satır değeri güncelle piece.isStart = true; // ilk hareket aktif et } } return(isMoveable + ";" + removeID); }
public ComputerPlayer(properties piece, moveC move) { this.pieceToMove = piece; this.moveToDo = move; }