} //Selecting or reselecting piece private void MovePices(int x, int y) { enPassantMade = false; if (allowedMoves[x, y]) { Pices c = piceses[x, y]; if (c != null && c.isWhite != isWhiteTurn) { //Removing pices from game activeChessPices.Remove(c.gameObject); Destroy(c.gameObject); if (c.GetType() == typeof(Konge)) { if (!isMinimaxing) { //win and end game GameEnded = true; EndGame(true); return; } } } //if there is an oponnent piece on place kill it if (x == enPassant[0] && y == enPassant[1]) { if (isWhiteTurn) { c = piceses[x, y - 1]; } else { c = piceses[x, y + 1]; } activeChessPices.Remove(c.gameObject); Destroy(c.gameObject); enPassantMade = true; }//destry if enPassan was made enPassant[0] = -1; enPassant[1] = -1; if (!MiniMaxing) { if (selectedPices.GetType() == typeof(Bunde)) { if (y == 7) { activeChessPices.Remove(selectedPices.gameObject); //removing pawn from active piceses Destroy(selectedPices.gameObject); //removing pawn from game SpawnChessPices(1, x, y, piceOrientationWhite); //Spawning rook in game selectedPices = piceses[x, y]; //selecting rook } //white promotion if (y == 0) { activeChessPices.Remove(selectedPices.gameObject); Destroy(selectedPices.gameObject); SpawnChessPices(7, x, y, piceOrientationBlack); selectedPices = piceses[x, y]; } //black promotion if (selectedPices.CurrentY == 1 && y == 3) { enPassant[0] = x; enPassant[1] = y - 1; } //saving pawn move for enPassant else if (selectedPices.CurrentY == 6 && y == 4) { enPassant[0] = x; enPassant[1] = y + 1; } //saving pawn move for enPassant } //Promotion } if (selectedPices.GetType() == typeof(Konge) && !selectedPices.HasMoved) //Rokade { if (x == 2 && y == 0) //white long Rokade { MoveHistory.Add(MakeMoveString(selectedPices, x, y)); //Moving king piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(x, y); selectedPices.SetPosition(x, y); piceses[x, y] = selectedPices; selectedPices.HasMoved = true; //Moving Rook selectedPices = piceses[0, 0]; piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(3, 0); selectedPices.SetPosition(3, 0); piceses[3, 0] = selectedPices; selectedPices.HasMoved = true; isWhiteTurn = !isWhiteTurn; BoardHeighlights.Instance.HideHighlights(); selectedPices = null; return; } else if (x == 6 && y == 0) //white short Rokade { MoveHistory.Add(MakeMoveString(selectedPices, x, y)); //Moving king piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(x, y); selectedPices.SetPosition(x, y); piceses[x, y] = selectedPices; selectedPices.HasMoved = true; //Moving Rook selectedPices = piceses[7, 0]; piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(5, 0); selectedPices.SetPosition(5, 0); piceses[5, 0] = selectedPices; selectedPices.HasMoved = true; isWhiteTurn = !isWhiteTurn; BoardHeighlights.Instance.HideHighlights(); selectedPices = null; return; } else if (x == 6 && y == 7) //black short Rokade { MoveHistory.Add(MakeMoveString(selectedPices, x, y)); //Moving king piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(x, y); selectedPices.SetPosition(x, y); piceses[x, y] = selectedPices; selectedPices.HasMoved = true; //Moving Rook selectedPices = piceses[7, 7]; piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(5, 7); selectedPices.SetPosition(5, 7); piceses[5, 7] = selectedPices; selectedPices.HasMoved = true; isWhiteTurn = !isWhiteTurn; BoardHeighlights.Instance.HideHighlights(); selectedPices = null; return; } else if (x == 2 && y == 7) //black long Rokade { MoveHistory.Add(MakeMoveString(selectedPices, x, y)); //Moving king piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(x, y); selectedPices.SetPosition(x, y); piceses[x, y] = selectedPices; selectedPices.HasMoved = true; //Moving Rook selectedPices = piceses[0, 7]; piceses[selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(3, 7); selectedPices.SetPosition(3, 7); piceses[3, 7] = selectedPices; selectedPices.HasMoved = true; isWhiteTurn = !isWhiteTurn; BoardHeighlights.Instance.HideHighlights(); selectedPices = null; return; } } //Rokade //moving piece and chaning turn MoveHistory.Add(MakeMoveString(selectedPices, x, y)); piceses [selectedPices.CurrentX, selectedPices.CurrentY] = null; selectedPices.transform.position = GetTileCenter(x, y); selectedPices.SetPosition(x, y); piceses [x, y] = selectedPices; selectedPices.HasMoved = true; //did pice make a check if (selectedPices.isWhite) { if (selectedPices.Check() != blackCheck) { blackCheck = !blackCheck; } } else { if (selectedPices.Check() != whiteCheck) { whiteCheck = !whiteCheck; } } isWhiteTurn = !isWhiteTurn; } BoardHeighlights.Instance.HideHighlights(); selectedPices = null; } //Moving Pice