/** * Update the game state according to move/command string from a player. * @param str The move or command to process. * @return True if str was understood, false otherwise. */ public bool processstring(string str) { if (handleCommand(str)) { return(true); } if (getGameState() != GameState.ALIVE) { return(false); } Move m = TextIO.stringToMove(pos, str); if (m == null) { return(false); } UndoInfo ui = new UndoInfo(); pos.makeMove(m, ui); TextIO.fixupEPSquare(pos); while (currentMove < moveList.Count) { moveList.RemoveAt(currentMove); uiInfoList.RemoveAt(currentMove); drawOfferList.RemoveAt(currentMove); } moveList.Add(m); uiInfoList.Add(ui); drawOfferList.Add(pendingDrawOffer); pendingDrawOffer = false; currentMove++; return(true); }
private bool handleDrawCmd(string drawCmd) { if (drawCmd.StartsWith("rep") || drawCmd.StartsWith("50")) { bool rep = drawCmd.StartsWith("rep"); Move m = null; string ms = drawCmd.Substring(drawCmd.IndexOf(" ") + 1); if (ms.Length > 0) { m = TextIO.stringToMove(pos, ms); } bool valid; if (rep) { valid = false; List <Position> oldPositions = new List <Position>(); Position tmpPos; if (m != null) { UndoInfo ui = new UndoInfo(); tmpPos = new Position(pos); tmpPos.makeMove(m, ui); oldPositions.Add(tmpPos); } oldPositions.Add(pos); tmpPos = pos; for (int i = currentMove - 1; i >= 0; i--) { tmpPos = new Position(tmpPos); tmpPos.unMakeMove(moveList[i], uiInfoList[i]); oldPositions.Add(tmpPos); } int repetitions = 0; Position firstPos = oldPositions[0]; for (int i = 0; i < oldPositions.Count; i++) { Position p = oldPositions[i]; if (p.drawRuleEquals(firstPos)) { repetitions++; } } if (repetitions >= 3) { valid = true; } } else { Position tmpPos = new Position(pos); if (m != null) { UndoInfo ui = new UndoInfo(); tmpPos.makeMove(m, ui); } valid = tmpPos.halfMoveClock >= 100; } if (valid) { drawState = rep ? GameState.DRAW_REP : GameState.DRAW_50; drawStateMoveStr = null; if (m != null) { drawStateMoveStr = TextIO.moveTostring(pos, m, false); } } else { pendingDrawOffer = true; if (m != null) { processstring(ms); } } return(true); } else if (drawCmd.StartsWith("offer ")) { pendingDrawOffer = true; string ms = drawCmd.Substring(drawCmd.IndexOf(" ") + 1); if (TextIO.stringToMove(pos, ms) != null) { processstring(ms); } return(true); } else if (drawCmd == "accept") { if (haveDrawOffer()) { drawState = GameState.DRAW_AGREE; } return(true); } else { return(false); } }