コード例 #1
0
 public long Place(string ticket, PlaceModel placeModel)
 {
     lock (mutex)
     {
         var ctx = GetContext(ticket);
         if (ctx != null &&
             chessboard != null &&
             !chessboard.GameOver &&
             ctx.Name == chessboard.CurrentPlayer)
         {
             var figure = chessboard.Get(placeModel.FromRow, placeModel.FromColumn);
             if (figure != null && figure.Color == chessboard.CurrentColor)
             {
                 foreach (var move in chessboard.GetAllMoves(figure, chessboard.Check))
                 {
                     if (move.Item1 == placeModel.ToRow && move.Item2 == placeModel.ToColumn)
                     {
                         if (IsComputerGame())
                         {
                             SendChessEngineUserMove(figure, placeModel);
                         }
                         // ok to move
                         if (chessboard.Place(figure, placeModel.ToRow, placeModel.ToColumn))
                         {
                             chessboard.UpdateState();
                             stateChanged = DateTime.UtcNow;
                         }
                         break;
                     }
                 }
             }
         }
         return(GetStateChanged());
     }
 }