public override string ToString() { StringBuilder sb = new StringBuilder(); // add top row of board. sb.Append(" "); for (int x = 0; x < this.BoardSize; x++) { sb.Append(" " + (char)(x + 'A') + " "); } // add line of '='s, sb.Append("\n "); sb.Append('=', 4 * this.BoardSize + 1); sb.Append("\n"); // add rest of board for (int y = 0; y < this.BoardSize; y++) { sb.Append((char)(y + 'a') + "|"); for (int x = 0; x < this.BoardSize; x++) { sb.Append(" "); sb.Append(DamkaPieces.GetSimpleType(this.Board[x, y])); sb.Append(" |"); } // add line of '='s, sb.Append("\n "); sb.Append('=', 4 * this.BoardSize + 1); sb.Append("\n"); } return(sb.ToString()); }
private void checkIfGameOver() { int sizeOfBlackPossibleMoves = 0; int sizeOfWhitePossibleMoves = 0; for (int y = 0; y < this.r_boardSize; y++) { for (int x = 0; x < this.r_boardSize; x++) { Point p = new Point(x, y); DamkaPieces.Type t = this.GetPieceByIndex(p); int count = this.GetLandingOptions(p).Count; if (DamkaPieces.GetKing(t) != DamkaPieces.Type.BlackKing) { sizeOfBlackPossibleMoves += count; } else if (DamkaPieces.GetKing(t) != DamkaPieces.Type.WhiteKing) { sizeOfWhitePossibleMoves += count; } } } if (sizeOfBlackPossibleMoves == 0) { this.IsGameOver = true; this.Winner = this.r_player2; } else if (sizeOfWhitePossibleMoves == 0) { this.IsGameOver = true; this.Winner = this.r_player1; } }
private bool isDistanceFitType(Point i_destination, Point i_origin) { bool isSkippable = (Math.Abs(i_destination.X - i_origin.X) == 1) && (Math.Abs(i_destination.Y - i_origin.Y) == 1); bool isKing = DamkaPieces.isKing(this.GetPieceByIndex(i_origin)); return(isKing || isSkippable); }
private bool isSkippableIndex(Point i_destination, Point i_origin) { bool isDistTwo = (Math.Abs(i_destination.X - i_origin.X) == 2) && (Math.Abs(i_destination.Y - i_origin.Y) == 2); bool isOpen = this.GetPieceByIndex(i_destination) == DamkaPieces.Type.None; Point p = new Point((i_destination.X + i_origin.X) / 2, (i_destination.Y + i_origin.Y) / 2); bool isSkippable = DamkaPieces.IsEnemyType(this.GetPieceByIndex(p), this.GetPieceByIndex(i_origin)); return(isDistTwo && isOpen && isSkippable); }
private void checkIfKingged(Point i_index) { DamkaPieces.Type type = this.GetPieceByIndex(i_index); bool hasReachedOtherSide = this.isSimplePieceOnOtherSide(i_index, type); if (hasReachedOtherSide) { this.placePieceAt(i_index, DamkaPieces.GetKing(type)); } }
private void checkIfEaten(Point i_index0, Point i_index1) { int howManySkipped = 0; int adder = (i_index1.X - i_index0.X > 0) ? -1 : 1; int deltaY = i_index0.Y - i_index1.Y; int deltaX = i_index0.X - i_index1.X; int m = deltaY / deltaX; int xLow = (i_index0.X < i_index1.X) ? i_index0.X : i_index1.X; int xHigh = (xLow == i_index1.X) ? i_index0.X : i_index1.X; int yOfLow = (xLow == i_index0.X) ? i_index0.Y : i_index1.Y; for (int x = i_index1.X + adder; x >= xLow && x <= xHigh; x = x + adder) { int y = m * (x - xLow) + yOfLow; DamkaPieces.Type tmp = this.GetPieceByIndex(new Point(x, y)); if (DamkaPieces.IsEnemyType(tmp, this.GetPieceByIndex(i_index1))) { if (this.isSkippableIndex(i_index0, i_index1)) { howManySkipped++; } } } if (howManySkipped == 1) { for (int x = i_index1.X + adder; x >= xLow && x <= xHigh; x = x + adder) { int y = m * (x - xLow) + yOfLow; Point p = new Point(x, y); DamkaPieces.Type tmp = this.GetPieceByIndex(p); if (DamkaPieces.IsEnemyType(tmp, this.GetPieceByIndex(i_index1))) { if (this.isSkippableIndex(i_index0, i_index1)) { this.placePieceAt(p, DamkaPieces.Type.None); } } } } }
private bool isIndexAbstractedByEnemy(Point i_destination, Point i_origin) { int adder = (i_origin.X - i_destination.X > 0) ? -1 : 1; int deltaY = i_destination.Y - i_origin.Y; int deltaX = i_destination.X - i_origin.X; int m = deltaY / deltaX; int xLow = (i_destination.X < i_origin.X) ? i_destination.X : i_origin.X; int xHigh = (xLow == i_origin.X) ? i_destination.X : i_origin.X; int yOfLow = (xLow == i_destination.X) ? i_destination.Y : i_origin.Y; int distance = 0; // count how many enemies between the points. int numberOfEnemiesInRange = 0; for (int x = i_origin.X + adder; x >= xLow && x <= xHigh; x = x + adder) { distance++; int y = m * (x - xLow) + yOfLow; DamkaPieces.Type tmp = this.GetPieceByIndex(new Point(x, y)); if (DamkaPieces.IsEnemyType(tmp, this.GetPieceByIndex(i_origin))) { numberOfEnemiesInRange++; } } bool isKing = DamkaPieces.isKing(this.GetPieceByIndex(i_origin)); bool result = false; if (isKing && numberOfEnemiesInRange == 1) { result = false; } else if (distance == 1 && numberOfEnemiesInRange == 1) { result = true; } return(result); }
private bool isIndexAbstractedByOtherPiece(Point i_destination, Point i_origin) { int adder = (i_origin.X - i_destination.X > 0) ? -1 : 1; int deltaY = i_destination.Y - i_origin.Y; int deltaX = i_destination.X - i_origin.X; int m = deltaY / deltaX; int xLow = (i_destination.X < i_origin.X) ? i_destination.X : i_origin.X; int xHigh = (xLow == i_origin.X) ? i_destination.X : i_origin.X; int yOfLow = (xLow == i_destination.X) ? i_destination.Y : i_origin.Y; for (int x = i_origin.X + adder; x >= xLow && x <= xHigh; x += adder) { int y = m * (x - xLow) + yOfLow; DamkaPieces.Type tmp = this.GetPieceByIndex(new Point(x, y)); if (DamkaPieces.IsSameType(tmp, this.GetPieceByIndex(i_origin))) { return(true); } } return(false); }