public CellMarkupStructure GetBackwardKnightFork(List <BoardCell> cellIdsList, int index) { FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index - 16; if (localIndex < 0) { return(localCellMarkupStruct); } CellMarkupStructure right = GetRightMoveCellsIdByCount(cellIdsList, localIndex, 1); CellMarkupStructure left = GetLeftMoveCellsIdByCount(cellIdsList, localIndex, 1); localCellMarkupStruct.canBeCapture = localCellMarkupStruct.canBeCapture .Concat(right.canBeCapture) .Concat(left.canBeCapture) .ToList(); localCellMarkupStruct.canBeDreggedTo = localCellMarkupStruct.canBeDreggedTo .Concat(right.canBeDreggedTo) .Concat(left.canBeDreggedTo) .ToList(); return(localCellMarkupStruct); }
public CellMarkupStructure GetLeftKnightFork(List <BoardCell> cellIdsList, int index) { int rowIndex = (int)(index / 8) + 1; int lowBoundary = ((rowIndex - 1) * 8); int hieBoundary = ((rowIndex) * 8) - 1; FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index - 2; if (localIndex > hieBoundary | localIndex < lowBoundary) { return(localCellMarkupStruct); } CellMarkupStructure forward = GetForwardMoveCellSIdByCount(cellIdsList, localIndex, 1); CellMarkupStructure backward = GetBackwardMoveCellSIdByCount(cellIdsList, localIndex, 1); localCellMarkupStruct.canBeCapture = localCellMarkupStruct.canBeCapture .Concat(forward.canBeCapture) .Concat(backward.canBeCapture) .ToList(); localCellMarkupStruct.canBeDreggedTo = localCellMarkupStruct.canBeDreggedTo .Concat(forward.canBeDreggedTo) .Concat(backward.canBeDreggedTo) .ToList(); return(localCellMarkupStruct); }
public CellMarkupStructure GetCellIdsOnWithCanBeDraged(List <BoardCell> cellIdsList, BoardCell boardCell) { CellMarkupStructure localCellIdsListBYType = new CellMarkupStructure().Init(); FigureTeamType teamType = figure.TeamType; BoardCellId currentCellId = boardCell.CellId; int index = cellIdsList.FindIndex(c => c.CellId == boardCell.CellId); if (index != -1) { CellMarkupStructure forwardFork = GetForwardKnightFork(cellIdsList, index); CellMarkupStructure backwardFork = GetBackwardKnightFork(cellIdsList, index); CellMarkupStructure rightFork = GetRightKnightFork(cellIdsList, index); CellMarkupStructure leftFork = GetLeftKnightFork(cellIdsList, index); localCellIdsListBYType.canBeCapture = localCellIdsListBYType.canBeCapture .Concat(forwardFork.canBeCapture) .Concat(backwardFork.canBeCapture) .Concat(rightFork.canBeCapture) .Concat(leftFork.canBeCapture) .ToList(); localCellIdsListBYType.canBeDreggedTo = localCellIdsListBYType.canBeDreggedTo .Concat(forwardFork.canBeDreggedTo) .Concat(backwardFork.canBeDreggedTo) .Concat(rightFork.canBeDreggedTo) .Concat(leftFork.canBeDreggedTo) .ToList(); } return(localCellIdsListBYType); }
public CellMarkupStructure GetCellIdsOnWithCanBeDraged(List <BoardCell> cellIdsList, BoardCell boardCell) { CellMarkupStructure localCellIdsListBYType = new CellMarkupStructure().Init(); FigureTeamType teamType = figure.TeamType; BoardCellId currentCellId = boardCell.CellId; int index = cellIdsList.FindIndex(c => c.CellId == boardCell.CellId); if (teamType == FigureTeamType.white) { CellMarkupStructure leftForward = GetForwardLeftMoveCellsIdByCount(cellIdsList, index, 1, false, true); CellMarkupStructure rightForward = GetForwardRightMoveCellsIdByCount(cellIdsList, index, 1, false, true); CellMarkupStructure forward = GetForwardMoveCellSIdByCount(cellIdsList, index, FirsMove ? 2 : 1, true, false); localCellIdsListBYType = forward; localCellIdsListBYType.canBeCapture = localCellIdsListBYType.canBeCapture.Concat(leftForward.canBeCapture).Concat(rightForward.canBeCapture).ToList(); } else { CellMarkupStructure leftForward = GetBackwardLeftMoveCellsIdByCount(cellIdsList, index, 1, false, true); CellMarkupStructure rightForward = GetBackwardRightMoveCellsIdByCount(cellIdsList, index, 1, false, true); CellMarkupStructure forward = GetBackwardMoveCellSIdByCount(cellIdsList, index, FirsMove ? 2 : 1, true, false); localCellIdsListBYType = forward; localCellIdsListBYType.canBeCapture = localCellIdsListBYType.canBeCapture.Concat(leftForward.canBeCapture).Concat(rightForward.canBeCapture).ToList(); } return(localCellIdsListBYType); }
public CellMarkupStructure GetCellIdsOnWithCanBeDraged(List <BoardCell> cellIdsList, BoardCell boardCell) { CellMarkupStructure localCellIdsListBYType = new CellMarkupStructure().Init(); BoardCellId currentCellId = boardCell.CellId; int index = cellIdsList.FindIndex(c => c.CellId == boardCell.CellId); if (index != -1) { CellMarkupStructure forwardRightList = GetForwardRightMoveCellsId(cellIdsList, index); CellMarkupStructure forwardLeftList = GetForwardLeftMoveCellsId(cellIdsList, index); CellMarkupStructure backwardLeftList = GetBackwardLeftMoveCellsId(cellIdsList, index); CellMarkupStructure backwardRightList = GetBackwardRightMoveCellsId(cellIdsList, index); localCellIdsListBYType.canBeCapture = localCellIdsListBYType.canBeCapture .Concat(forwardRightList.canBeCapture) .Concat(forwardLeftList.canBeCapture) .Concat(backwardLeftList.canBeCapture) .Concat(backwardRightList.canBeCapture) .ToList(); localCellIdsListBYType.canBeDreggedTo = localCellIdsListBYType.canBeDreggedTo .Concat(forwardRightList.canBeDreggedTo) .Concat(forwardLeftList.canBeDreggedTo) .Concat(backwardLeftList.canBeDreggedTo) .Concat(backwardRightList.canBeDreggedTo) .ToList(); } return(localCellIdsListBYType); }
private bool isCastle(BoardCell boardCell, CellMarkupStructure cellMarkup) { int canBeCastleCouresponeCellIndex = cellMarkup.canBeCastle.FindIndex(castleStruct => castleStruct.KingTo == boardCell.CellId); if (canBeCastleCouresponeCellIndex != -1) { return(true); } return(false); }
public CellMarkupStructure GetLeftCastleCellsId(List <BoardCell> cellIdsList, int index) { int rowIndex = (int)(index / 8) + 1; int lowBoundary = ((rowIndex - 1) * 8); int hieBoundary = ((rowIndex) * 8) - 1; FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index; BoardCellId kingPosition = cellIdsList[index].CellId; CellMarkupStructure endPositionOfKingAndRook = GetLeftMoveCellsIdByCount(cellIdsList, index, 2, true, false); if (endPositionOfKingAndRook.canBeDreggedTo.Count != 2) { return(localCellMarkupStruct); } BoardCellId kingEndPosition = endPositionOfKingAndRook.canBeDreggedTo[1]; BoardCellId rookEndPosition = endPositionOfKingAndRook.canBeDreggedTo[0]; do { BoardCell boardCell = GetLeftCell(cellIdsList, ref localIndex, lowBoundary, hieBoundary); if (boardCell != null) { if (boardCell.figureOnCell == null) { continue; } else { Rook localRook = boardCell.figureOnCell.GetComponent <Rook>(); if (localRook == null) { break; } if (localRook.FirsMove) { CastleStructure localCastleStructure = new CastleStructure(); localCastleStructure.Init(kingPosition, kingEndPosition, boardCell.CellId, rookEndPosition); localCellMarkupStruct.canBeCastle.Add(localCastleStructure); break; } else { break; } } } else { break; } } while (true); return(localCellMarkupStruct); }
public bool CellInAvalibleList(BoardCell boardCell, CellMarkupStructure cellMarkup) { int canBeDreggedCouresponeCellIndex = cellMarkup.canBeDreggedTo.FindIndex(id => id == boardCell.CellId); int canBeCapturCouresponeCellIndex = cellMarkup.canBeCapture.FindIndex(id => id == boardCell.CellId); int canBeCastleCouresponeCellIndex = cellMarkup.canBeCastle.FindIndex(castleStruct => castleStruct.KingTo == boardCell.CellId); if (canBeDreggedCouresponeCellIndex != -1 || canBeCapturCouresponeCellIndex != -1 || canBeCastleCouresponeCellIndex != -1) { return(true); } return(false); }
public CellMarkupStructure GetCellIdsOnWithCanBeDraged(List <BoardCell> cellIdsList, BoardCell boardCell) { CellMarkupStructure localCellIdsListBYType = new CellMarkupStructure().Init(); FigureTeamType teamType = figure.TeamType; BoardCellId currentCellId = boardCell.CellId; int index = cellIdsList.FindIndex(c => c.CellId == boardCell.CellId); if (index != -1) { CellMarkupStructure forward = GetForwardMoveCellSIdByCount(cellIdsList, index, 1); CellMarkupStructure backward = GetBackwardMoveCellSIdByCount(cellIdsList, index, 1); CellMarkupStructure right = GetRightMoveCellsIdByCount(cellIdsList, index, 1); CellMarkupStructure left = GetLeftMoveCellsIdByCount(cellIdsList, index, 1); CellMarkupStructure forwardLeft = GetForwardLeftMoveCellsIdByCount(cellIdsList, index, 1); CellMarkupStructure forwardRight = GetForwardRightMoveCellsIdByCount(cellIdsList, index, 1); CellMarkupStructure backwardLeft = GetBackwardLeftMoveCellsIdByCount(cellIdsList, index, 1); CellMarkupStructure backwardRight = GetBackwardRightMoveCellsIdByCount(cellIdsList, index, 1); localCellIdsListBYType.canBeCapture = localCellIdsListBYType.canBeCapture .Concat(forward.canBeCapture) .Concat(backward.canBeCapture) .Concat(right.canBeCapture) .Concat(left.canBeCapture) .Concat(forwardLeft.canBeCapture) .Concat(forwardRight.canBeCapture) .Concat(backwardLeft.canBeCapture) .Concat(backwardRight.canBeCapture) .ToList(); localCellIdsListBYType.canBeDreggedTo = localCellIdsListBYType.canBeDreggedTo .Concat(forward.canBeDreggedTo) .Concat(backward.canBeDreggedTo) .Concat(right.canBeDreggedTo) .Concat(left.canBeDreggedTo) .Concat(forwardLeft.canBeDreggedTo) .Concat(forwardRight.canBeDreggedTo) .Concat(backwardLeft.canBeDreggedTo) .Concat(backwardRight.canBeDreggedTo) .ToList(); if (FirsMove) { CellMarkupStructure castleLeft = GetLeftCastleCellsId(cellIdsList, index); CellMarkupStructure castleRight = GetRightCastleCellsId(cellIdsList, index); localCellIdsListBYType.canBeCastle = localCellIdsListBYType.canBeCastle .Concat(castleLeft.canBeCastle) .Concat(castleRight.canBeCastle) .ToList(); } } return(localCellIdsListBYType); }
public CellMarkupStructure GetLeftMoveCellsIdByCount(List <BoardCell> cellIdsList, int index, int count, bool canBeDragged = true, bool canBeCapture = true) { int rowIndex = (int)(index / 8) + 1; int lowBoundary = ((rowIndex - 1) * 8); int hieBoundary = ((rowIndex) * 8) - 1; FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index; for (int i = 0; i < count; i++) { BoardCell boardCell = GetLeftCell(cellIdsList, ref localIndex, lowBoundary, hieBoundary); if (boardCell != null) { if (boardCell.figureOnCell != null) { Figure localFigureOnCell = boardCell.figureOnCell.GetComponent <Figure>(); if (localFigureOnCell.TeamType == figureTeamType) { break; } else { if (canBeCapture) { localCellMarkupStruct.canBeCapture.Add(boardCell.CellId); } break; } } else { if (canBeDragged) { localCellMarkupStruct.canBeDreggedTo.Add(boardCell.CellId); } } } else { break; } } return(localCellMarkupStruct); }
public CellMarkupStructure GetBackwardMoveCellSIdByCount(List <BoardCell> cellIdsList, int index, int count, bool canBeDragged = true, bool canBeCapture = true) { FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index; for (int i = 0; i < count; i++) { BoardCell boardCell = GetBackwardCell(cellIdsList, ref localIndex); if (boardCell != null) { if (boardCell.figureOnCell != null) { Figure localFigureOnCell = boardCell.figureOnCell.GetComponent <Figure>(); if (localFigureOnCell.TeamType == figureTeamType) { break; } else { if (canBeCapture) { localCellMarkupStruct.canBeCapture.Add(boardCell.CellId); } break; } } else { if (canBeDragged) { localCellMarkupStruct.canBeDreggedTo.Add(boardCell.CellId); } } } else { break; } } return(localCellMarkupStruct); }
public void ResetCellsMarkAsADefault(CellMarkupStructure cellMarkup) { foreach (var cell in BoardCellsList) { int canBeDreggedCouresponeCellIndex = cellMarkup.canBeDreggedTo.FindIndex(id => id == cell.CellId); int canBeCapturCouresponeCellIndex = cellMarkup.canBeCapture.FindIndex(id => id == cell.CellId); int canBeCastleCouresponeCellIndex = cellMarkup.canBeCastle.FindIndex(castleStruct => castleStruct.KingTo == cell.CellId); if (canBeDreggedCouresponeCellIndex != -1) { cell.ResetCellMark(); } if (canBeCapturCouresponeCellIndex != -1) { cell.ResetCellMark(); } if (canBeCastleCouresponeCellIndex != -1) { cell.ResetCellMark(); } } }
public void MarkCellsByType(CellMarkupStructure cellMarkup) { foreach (var cell in BoardCellsList) { int canBeDreggedCouresponeCellIndex = cellMarkup.canBeDreggedTo.FindIndex(id => id == cell.CellId); int canBeCapturCouresponeCellIndex = cellMarkup.canBeCapture.FindIndex(id => id == cell.CellId); int canBeCastleCouresponeCellIndex = cellMarkup.canBeCastle.FindIndex(castleStruct => castleStruct.KingTo == cell.CellId); if (canBeDreggedCouresponeCellIndex != -1) { cell.MarkAsCanBeDragger(); } if (canBeCapturCouresponeCellIndex != -1) { cell.MarkAsCanBeCapture(); } if (canBeCastleCouresponeCellIndex != -1) { cell.MarkAsCastled(); } } }
public CellMarkupStructure GetLeftMoveCellsId(List <BoardCell> cellIdsList, int index) { int rowIndex = (int)(index / 8) + 1; int lowBoundary = ((rowIndex - 1) * 8); int hieBoundary = ((rowIndex) * 8) - 1; FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index; do { BoardCell boardCell = GetLeftCell(cellIdsList, ref localIndex, lowBoundary, hieBoundary); if (boardCell != null) { if (boardCell.figureOnCell != null) { Figure localFigureOnCell = boardCell.figureOnCell.GetComponent <Figure>(); if (localFigureOnCell.TeamType == figureTeamType) { break; } else { localCellMarkupStruct.canBeCapture.Add(boardCell.CellId); break; } } else { localCellMarkupStruct.canBeDreggedTo.Add(boardCell.CellId); } } else { break; } } while (true); return(localCellMarkupStruct); }
public CellMarkupStructure GetBackwardLeftMoveCellsId(List <BoardCell> cellIdsList, int index) { FigureTeamType figureTeamType = figure.TeamType; CellMarkupStructure localCellMarkupStruct = new CellMarkupStructure().Init(); int localIndex = index; do { BoardCell boardCell = GetBackwardLeftCell(cellIdsList, ref localIndex); if (boardCell != null) { if (boardCell.figureOnCell != null) { Figure localFigureOnCell = boardCell.figureOnCell.GetComponent <Figure>(); if (localFigureOnCell.TeamType == figureTeamType) { break; } else { localCellMarkupStruct.canBeCapture.Add(boardCell.CellId); break; } } else { localCellMarkupStruct.canBeDreggedTo.Add(boardCell.CellId); } } else { break; } } while (true); return(localCellMarkupStruct); }
private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool hasHit = Physics.Raycast(ray, out hit); if (hasHit) { BoardCell boardCell = hit.collider.gameObject.GetComponent <BoardCell>(); if ((boardCell != null && boardCell.figureOnCell == null && selectedBoardSell == null) || boardCell == null) { return; } if (selectedBoardSell != null && !isCellMarkapEmpty() && selectedBoardSell.CellId == boardCell.CellId) { selectedBoardSell.ResetCellMark(); ResetCellsMarkAsADefault(markCellsAsCanBeDragToList); selectedBoardSell = null; ResetMarksCells(); } else if (selectedBoardSell != null && !isCellMarkapEmpty() && selectedBoardSell.CellId != boardCell.CellId) { // if you with selected your's figure // 1 select your figure it will reset selection // 2 select avalible drag cell it will relocat it // Relocat Figure if (CellInAvalibleList(boardCell, markCellsAsCanBeDragToList)) { if (isCastle(boardCell, markCellsAsCanBeDragToList)) { MakeCastle(selectedBoardSell, boardCell); } else { RelocateFigureToCell(selectedBoardSell, boardCell); } selectedBoardSell.ResetCellMark(); ResetCellsMarkAsADefault(markCellsAsCanBeDragToList); selectedBoardSell = null; ResetMarksCells(); } else { if (boardCell.figureOnCell != null) { selectedBoardSell.ResetCellMark(); ResetCellsMarkAsADefault(markCellsAsCanBeDragToList); boardCell.MarkAsSelected(); selectedBoardSell = boardCell; CellMarkupStructure draggableCellIds = boardCell.figureOnCell.GetComponent <IFigure>().GetCellIdsOnWithCanBeDraged(BoardCellsList, boardCell); markCellsAsCanBeDragToList = draggableCellIds; MarkCellsByType(draggableCellIds); } } } else { if (boardCell.figureOnCell.GetComponent <Figure>().TeamType == currentTeamTurn) { boardCell.MarkAsSelected(); selectedBoardSell = boardCell; CellMarkupStructure draggableCellIds = boardCell.figureOnCell.GetComponent <IFigure>().GetCellIdsOnWithCanBeDraged(BoardCellsList, boardCell); markCellsAsCanBeDragToList = draggableCellIds; MarkCellsByType(draggableCellIds); } } } } }