public static List <ChessPosition> ToList(this ChessBoardSnapshot boardSnapshot) { List <ChessPosition> ret = new List <ChessPosition>(); if (boardSnapshot == null) { return(ret); } ChessPieceType[] board = boardSnapshot.board; bool[] hasMoved = boardSnapshot.hasMoved; if (board.Length != ChessSettings.boardSize * ChessSettings.boardSize) { return(ret); } for (int i = 0; i < board.Length; i++) { if (!board[i].IsValid()) { continue; } if (board[i].IsEmpty()) { continue; } ChessPosition newPos = new ChessPosition { coord = i.ToChessCoord(), type = board[i], hasMoved = hasMoved[i] }; ret.Add(newPos); } return(ret); }
public static bool IsEndGame(this ChessBoardSnapshot boardSnapshot) { bool isOneKingAlive = false; ChessPieceType[] board = boardSnapshot.board; for (int i = 0; i < board.Length; i++) { if (board[i].IsKing()) { if (!isOneKingAlive) { isOneKingAlive = true; } else { return(false); } } } return(true); }