public IActionResult Index(int initialX, int initialY, int instantaneousX, int instantaneousY, string count, int color, string onMessage) { if (onMessage == "Update") { board = HttpContext.Session.GetObject <Board>(count); model.Squares = board.AllSquares; model.Counter = count; model.Color = color; return(View(model)); } board = HttpContext.Session.GetObject <Board>(count); board.TakeBackCastAll(); Square secondClickSquare = board.AllSquares.Select(t => t).Where(t => t.Coordinate.X == instantaneousX && t.Coordinate.Y == instantaneousY).FirstOrDefault(); if (secondClickSquare != null) { if (secondClickSquare.Coordinate.X == instantaneousX && secondClickSquare.Coordinate.Y == instantaneousY) { Square firstClickSquare = board.AllSquares.Select(t => t).Where(t => t.Coordinate.X == initialX && t.Coordinate.Y == initialY).FirstOrDefault(); if (firstClickSquare.Piece != null && (int)firstClickSquare.Piece.Color == color) { if (firstClickSquare.Piece.Touchable == false) { King king = (King)firstClickSquare.Piece; king.CheckCounterPiece(secondClickSquare, board); if (firstClickSquare.Coordinate.X == 4 && (firstClickSquare.Coordinate.Y == 1 || firstClickSquare.Coordinate.Y == 8) && secondClickSquare.Coordinate.X == 2 && (secondClickSquare.Coordinate.Y == 1 || secondClickSquare.Coordinate.Y == 8)) { if (!king.ShortCastle(board)) { if (onMessage == "Yes") { color = 1 - color; } board.CastAll(); HttpContext.Session.SetObject(count, board); model.Squares = board.AllSquares; model.Counter = count; model.Color = color; return(View(model)); } } else if (firstClickSquare.Coordinate.X == 4 && (firstClickSquare.Coordinate.Y == 1 || firstClickSquare.Coordinate.Y == 8) && secondClickSquare.Coordinate.X == 6 && (secondClickSquare.Coordinate.Y == 1 || secondClickSquare.Coordinate.Y == 8)) { if (!king.LongCastle(board)) { if (onMessage == "Yes") { color = 1 - color; } board.CastAll(); HttpContext.Session.SetObject(count, board); model.Squares = board.AllSquares; model.Counter = count; model.Color = color; return(View(model)); } } } if (firstClickSquare.Piece != null) { if (firstClickSquare.Piece.MoveTo(secondClickSquare, board)) { if (!secondClickSquare.Piece.DiscoverCheckToMove(board)) { secondClickSquare.Piece.MoveBack = true; secondClickSquare.Piece.MoveTo(firstClickSquare, board); } else { secondClickSquare.Piece.StateOrder(board); } } } if (onMessage == "Yes") { color = 1 - color; } board.CastAll(); HttpContext.Session.SetObject(count, board); model.Squares = board.AllSquares; model.Counter = count; model.Color = color; return(View(model)); } } } if (onMessage == "Yes") { color = 1 - color; } board.CastAll(); HttpContext.Session.SetObject(count, board); model.Squares = board.AllSquares; model.Counter = count; model.Color = color; return(View(model)); }