/// <summary> /// CSA形式の指し手を特殊な指し手に変換します。 /// </summary> public static BoardMove CsaToSpecialMove(this Board board, string csa) { var m = SpecialMoveRegex.Match(csa); if (!m.Success) { return(null); } var smoveType = SpecialMoveType.None; switch (m.Groups[1].Value) { case "CHUDAN": smoveType = SpecialMoveType.Interrupt; break; case "TORYO": smoveType = SpecialMoveType.Resign; break; case "SENNICHITE": smoveType = SpecialMoveType.Sennichite; break; case "OUTE_SENNICHITE": smoveType = SpecialMoveType.OuteSennichite; break; case "ILLEGAL_MOVE": smoveType = SpecialMoveType.IllegalMove; break; case "TIME_UP": smoveType = SpecialMoveType.TimeUp; break; case "JISHOGI": smoveType = SpecialMoveType.Jishogi; break; case "TSUMI": smoveType = SpecialMoveType.CheckMate; break; case "ERROR": smoveType = SpecialMoveType.Error; break; default: throw new CsaException( m.Groups[1].Value + ": 対応していないCSA形式の指し手です。"); } return(BoardMove.CreateSpecialMove(board.Turn, smoveType)); }
public void SpecialMoveTest() { var move = BoardMove.CreateSpecialMove(BWType.Black, SpecialMoveType.Interrupt); Assert.Catch <SfenException>(() => move.ToSfen()); }
public void SerializeTest() { // すべてのマスをテストすると時間がかかりすぎるため、 // 移動元・移動先共にテストするマスを絞っています。 var validMoveList = from turn in new BWType[] { BWType.Black, BWType.White } from dst in Board.AllSquares() from src in Board.AllSquares() from pc in EnumEx.GetValues <PieceType>() from promoted in new bool[] { false, true } from tookPc in EnumEx.GetValues <PieceType>() from tookPromoted in new bool[] { false, true } from promote in new bool[] { false, true } let pcPiece = new Piece(pc, promoted) let tookPiece = (tookPc != PieceType.None ? new Piece(tookPc, tookPromoted) : null) where pcPiece.Validate() where tookPiece == null || tookPiece.Validate() where (dst.Rank % 2) == 1 && (dst.File % 3) == 1 where (src.Rank % 2) == 1 && (src.File % 3) == 1 let bmove = BoardMove.CreateMove( turn, src, dst, pcPiece, promote, tookPiece) where bmove.Validate() select bmove; var validDropList = from turn in new BWType[] { BWType.Black, BWType.White } from dst in Board.AllSquares() from pc in EnumEx.GetValues <PieceType>() where pc != PieceType.None let bmove = BoardMove.CreateDrop(turn, dst, pc) where bmove.Validate() select bmove; var specialMoveList = from turn in new BWType[] { BWType.Black, BWType.White } from special in EnumEx.GetValues <SpecialMoveType>() where special != SpecialMoveType.None let bmove = BoardMove.CreateSpecialMove(turn, special) where bmove.Validate() select bmove; var count = 0; var moveList = validMoveList.Concat(validDropList).Concat(specialMoveList); foreach (var bmove in moveList) { var bytes = PbUtil.Serialize(bmove); Assert.NotNull(bytes); var newMove = PbUtil.Deserialize <BoardMove>(bytes); Assert.NotNull(newMove); Assert.True(newMove.Validate()); Assert.AreEqual(bmove, newMove); // 多くのテストがあるため、一応 if (count++ % 50000 == 0) { Console.WriteLine("BoardMoveTest.SerializeTest testing..."); } } }