public override bool IsMoveable(Position destination) { //Check if the destination cell is not busy of Alliance unit foreach (var unit in InitializedTeams.allianceTeam) { if (destination.col == unit.ColPosition && destination.row == unit.RowPosition) { return false; } } int deltaRow = destination.row - this.RowPosition; int deltaCol = destination.col - this.ColPosition; //invalid move if (Math.Abs(deltaCol) > 1 || Math.Abs(deltaRow) > 1) { return false; } return true; }
public override bool IsMoveable(Position destination) { //Check if the destination cell is not busy of Alliance unit foreach (var unit in InitializedTeams.allianceTeam) { if (destination.col == unit.ColPosition && destination.row == unit.RowPosition) { return false; } } int deltaRow = (int)Math.Abs(destination.row - this.RowPosition); int deltaCol = (int)Math.Abs(destination.col - this.ColPosition); //Check if the destination cell is corresponding to the unit move rules if ((deltaRow == 2 && deltaCol == 1) || (deltaRow == 1 && deltaCol == 2)) { return true; } return false; }
public virtual bool IsMoveable(Position destination) { throw new NotImplementedException(); }
public override bool IsMoveable(Position destination) { //Check if the destination cell is not busy of Alliance unit foreach (var unit in InitializedTeams.allianceTeam) { if (destination.col == unit.ColPosition && destination.row == unit.RowPosition) { return false; } } int deltaRow = destination.row - this.RowPosition; int deltaCol = destination.col - this.ColPosition; //Check horizonal line if it's clear to move if (deltaRow == 0) { if (deltaCol > 0) { for (int currentCol = this.ColPosition + 1; currentCol <= destination.col; currentCol++) { foreach (var unit in InitializedTeams.allianceTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == this.RowPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == this.RowPosition) { return false; } } } return true; } if (deltaCol < 0) { for (int currentCol = this.ColPosition - 1; currentCol >= destination.col; currentCol--) { foreach (var unit in InitializedTeams.allianceTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == this.RowPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == this.RowPosition) { return false; } } } return true; } } //Check vertical line if it's clear to move else if (deltaCol == 0) { if (deltaRow > 0) { for (int currentRow = this.RowPosition + 1; currentRow <= destination.row; currentRow++) { foreach (var unit in InitializedTeams.allianceTeam) { if (unit.RowPosition == currentRow && unit.ColPosition == this.ColPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (unit.RowPosition == currentRow && unit.ColPosition == this.ColPosition) { return false; } } } return true; } if (deltaRow < 0) { for (int currentRow = this.RowPosition - 1; currentRow >= destination.row; currentRow--) { foreach (var unit in InitializedTeams.allianceTeam) { if (unit.RowPosition == currentRow && unit.ColPosition == this.ColPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (unit.RowPosition == currentRow && unit.ColPosition == this.ColPosition) { return false; } } } return true; } } // Check diagonal line if it's clear to move else if (Math.Abs(deltaRow) == Math.Abs(deltaCol)) { int currentRow = this.RowPosition; int currentCol = this.ColPosition; for (int i = 0; i < Math.Abs(deltaRow); i++) { if (deltaRow < 0 && deltaCol < 0) { currentCol--; currentRow--; foreach (var unit in InitializedTeams.allianceTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } } else if (deltaRow < 0 && deltaCol > 0) { currentCol++; currentRow--; foreach (var unit in InitializedTeams.allianceTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } } else if (deltaRow > 0 && deltaCol > 0) { currentCol++; currentRow++; foreach (var unit in InitializedTeams.allianceTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } } else if (deltaRow > 0 && deltaCol < 0) { currentCol--; currentRow++; foreach (var unit in InitializedTeams.allianceTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (currentRow == unit.RowPosition && currentCol == unit.ColPosition) { return false; } } } } return true; } return false; }
public override bool IsMoveable(Position destination) { //Check if the destination cell is not busy of Alliance unit foreach (var unit in InitializedTeams.allianceTeam) { if (destination.col == unit.ColPosition && destination.row == unit.RowPosition) { return false; } } int deltaRow = destination.row - this.RowPosition; int deltaCol = destination.col - this.ColPosition; //Invalid move if (deltaCol != 0 && deltaRow != 0) { return false; } else if (deltaCol == 0) { int currentRow = this.RowPosition; int currentCol = this.ColPosition; for (int i = 0; i < Math.Abs(deltaRow); i++) { if (deltaRow < 0) { currentRow--; } else { currentRow++; } foreach (var unit in InitializedTeams.allianceTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == currentRow) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == currentRow) { return false; } } } return true; } else if (deltaRow == 0) { int currentRow = this.RowPosition; int currentCol = this.ColPosition; for (int i = 0; i < Math.Abs(deltaCol); i++) { if (deltaCol < 0) { currentCol--; } else { currentCol++; } foreach (var unit in InitializedTeams.allianceTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == currentRow) { return false; } } foreach (var unit in InitializedTeams.hordeTeam) { if (unit.ColPosition == currentCol && unit.RowPosition == currentRow) { return false; } } } return true; } return false; }