public static ChineseChessPosition FindFirstOpponentOnColumn(Int32 curCol, Int32 startRow, Dictionary <ChineseChessPosition, Boolean> boardStates, Boolean increase) { Int32 nRow = startRow; if (increase) { for (; nRow <= ChineseChessPosition.MaximumRow; nRow++) { ChineseChessPosition pos = new ChineseChessPosition() { Row = nRow, Column = curCol }; if (boardStates.ContainsKey(pos)) { if (boardStates[pos]) { return(null); } else { return(pos); } } } } else { for (; nRow >= ChineseChessPosition.MinimumRow; nRow--) { ChineseChessPosition pos = new ChineseChessPosition() { Row = nRow, Column = curCol }; if (boardStates.ContainsKey(pos)) { if (boardStates[pos]) { return(null); } else { return(pos); } } } } return(null); }
public static ChineseChessPosition FindFirstOpponentOnRow(Int32 curRow, Int32 startCol, Dictionary <ChineseChessPosition, Boolean> boardStates, Boolean increase) { Int32 nCol = startCol; if (increase) { for (; nCol <= ChineseChessPosition.MaximumColumn; nCol++) { ChineseChessPosition pos = new ChineseChessPosition() { Row = curRow, Column = nCol }; if (boardStates.ContainsKey(pos)) { if (boardStates[pos]) { return(null); } else { return(pos); } } } } else { for (; nCol >= ChineseChessPosition.MinimumColumn; nCol--) { ChineseChessPosition pos = new ChineseChessPosition() { Row = curRow, Column = nCol }; if (boardStates.ContainsKey(pos)) { if (boardStates[pos]) { return(null); } else { return(pos); } } } } return(null); }
private void CaptureOppoPiece(ChineseChessPosition pos) { Int32 idx = -1; for (var i = 0; i < OppoPieces.Count; i++) { if (OppoPieces[i].Position == pos) { idx = i; break; } } if (idx != -1) { OppoPieces.RemoveAt(idx); } }
public ChineseChessPiece(String name = null, Int32?row = null, Int32?column = null) { Position = new ChineseChessPosition(); if (!String.IsNullOrEmpty(name)) { Name = name; } if (row != null) { Position.Row = row.Value; } if (column != null) { Position.Column = column.Value; } }
public void MovePieceTo(ChineseChessPiece piece, ChineseChessPosition pos, Boolean?isCapture) { piece.MoveToPosition(pos); Boolean bCap = false; if (isCapture == null) { foreach (var piece2 in OppoPieces) { if (piece2.Position == pos) { bCap = true; break; } } } if (bCap) { CaptureOppoPiece(pos); } }
public void MoveToPosition(ChineseChessPosition pos) { Position.Row = pos.Row; Position.Column = pos.Column; }
public static List <ChineseChessPosition> PossibleMovesForPao(Int32 curRow, Int32 curCol, Dictionary <ChineseChessPosition, Boolean> boardStates) { List <ChineseChessPosition> listMoves = new List <ChineseChessPosition>(); for (Int32 i = curRow + 1; i <= ChineseChessPosition.MaximumRow; i++) { ChineseChessPosition pos = new ChineseChessPosition() { Row = i, Column = curCol }; if (boardStates.ContainsKey(pos)) { ChineseChessPosition next = FindFirstOpponentOnColumn(curCol, i + 1, boardStates, true); if (next != null) { listMoves.Add(next); } break; } listMoves.Add(pos); } for (Int32 j = curRow - 1; j >= ChineseChessPosition.MinimumRow; j--) { ChineseChessPosition pos = new ChineseChessPosition() { Row = j, Column = curCol }; if (boardStates.ContainsKey(pos)) { ChineseChessPosition next = FindFirstOpponentOnColumn(curCol, j - 1, boardStates, false); if (next != null) { listMoves.Add(next); } break; } listMoves.Add(pos); } for (Int32 i = curCol + 1; i <= ChineseChessPosition.MaximumColumn; i++) { ChineseChessPosition pos = new ChineseChessPosition() { Row = curRow, Column = i }; if (boardStates.ContainsKey(pos)) { ChineseChessPosition next = FindFirstOpponentOnColumn(curRow, i + 1, boardStates, true); if (next != null) { listMoves.Add(next); } break; } listMoves.Add(pos); } for (Int32 j = curCol - 1; j >= ChineseChessPosition.MinimumColumn; j--) { ChineseChessPosition pos = new ChineseChessPosition() { Row = curRow, Column = j }; if (boardStates.ContainsKey(pos)) { ChineseChessPosition next = FindFirstOpponentOnColumn(curRow, j - 1, boardStates, false); if (next != null) { listMoves.Add(next); } break; } listMoves.Add(pos); } return(listMoves); }
public static List <ChineseChessPosition> MovesOnSameLine(Int32 curRow, Int32 curCol, Dictionary <ChineseChessPosition, Boolean> boardStates) { List <ChineseChessPosition> listMoves = new List <ChineseChessPosition>(); for (Int32 i = curRow + 1; i <= ChineseChessPosition.MaximumRow; i++) { ChineseChessPosition pos = new ChineseChessPosition() { Row = i, Column = curRow }; if (boardStates.ContainsKey(pos)) { if (!boardStates[pos]) { listMoves.Add(pos); } break; } listMoves.Add(pos); } for (Int32 j = curRow - 1; j >= ChineseChessPosition.MinimumRow; j--) { ChineseChessPosition pos = new ChineseChessPosition() { Row = j, Column = curCol }; if (boardStates.ContainsKey(pos)) { if (!boardStates[pos]) { listMoves.Add(pos); } break; } listMoves.Add(pos); } for (Int32 i = curCol + 1; i <= ChineseChessPosition.MaximumColumn; i++) { ChineseChessPosition pos = new ChineseChessPosition() { Row = curRow, Column = i }; if (boardStates.ContainsKey(pos)) { if (!boardStates[pos]) { listMoves.Add(pos); } } listMoves.Add(pos); } for (Int32 j = curCol - 1; j >= ChineseChessPosition.MinimumColumn; j--) { ChineseChessPosition pos = new ChineseChessPosition() { Row = curRow, Column = j }; if (boardStates.ContainsKey(pos)) { if (!boardStates[pos]) { listMoves.Add(pos); } break; } listMoves.Add(pos); } return(listMoves); }