Commit 2af1b9c5 by Paktalin

6.1 complete

parent 502537f3
...@@ -31,9 +31,11 @@ class Board { ...@@ -31,9 +31,11 @@ class Board {
void placePiece(Piece piece, String position) { void placePiece(Piece piece, String position) {
layout.placePiece(piece, position); layout.placePiece(piece, position);
} }
Piece getPieceAtPosition(String position) { Piece getPieceAtPosition(String position) {
return layout.getPieceAtPosition(position); return layout.getPieceAtPosition(position);
} }
String print() { String print() {
return layout.print(); return layout.print();
} }
...@@ -41,6 +43,7 @@ class Board { ...@@ -41,6 +43,7 @@ class Board {
void addToCollection(Piece piece) { void addToCollection(Piece piece) {
getSide(piece.getColor()).addPiece(piece); getSide(piece.getColor()).addPiece(piece);
} }
private Side getSide(Piece.Color color){ private Side getSide(Piece.Color color){
if (color == White) if (color == White)
return whiteSide; return whiteSide;
......
...@@ -23,45 +23,38 @@ public class Piece implements Comparable<Piece>{ ...@@ -23,45 +23,38 @@ public class Piece implements Comparable<Piece>{
this.type = type; this.type = type;
} }
public Color getColor() {
return color;
}
Type getType() {
return type;
}
char getRepresentation() { char getRepresentation() {
char representation = 0; char representation = getRepresentationLetter();
if (type == Type.King)
representation = 'k';
if (type == Type.Queen)
representation = 'q';
if (type == Type.Pawn)
representation = 'p';
if (type == Type.Rook)
representation = 'r';
if (type == Type.Bishop)
representation = 'b';
if (type == Type.Knight)
representation = 'n';
if (this.isBlack()) if (this.isBlack())
return Character.toUpperCase(representation); return Character.toUpperCase(representation);
return representation; return representation;
} }
private char getRepresentationLetter() {
switch (this.type) {
case Knight: return 'n';
case King: return 'k';
case Queen: return 'q';
case Rook: return 'r';
case Bishop: return 'b';
default: return 'p';
}
}
void setStrength(double strength) {
this.strength = strength;
}
void setStrength() { void setStrength() {
if (type == Type.Queen) strength = calculateStrength();
strength = 9; }
if (type == Type.Rook)
strength = 5; private double calculateStrength() {
if (type == Type.Bishop) switch (this.type) {
strength = 3; case Queen: return 9;
if (type == Type.Knight) case Rook: return 5;
strength = 2.5; case Bishop: return 3;
if (type == Type.King) case Knight: return 2.5;
strength = 0.0; default: return 0;
}
} }
@Override @Override
...@@ -73,13 +66,15 @@ public class Piece implements Comparable<Piece>{ ...@@ -73,13 +66,15 @@ public class Piece implements Comparable<Piece>{
return 0; return 0;
} }
void setStrength(double strength) {
this.strength = strength;
}
double getStrength() { double getStrength() {
return strength; return strength;
} }
public Color getColor() {
return color;
}
Type getType() {
return type;
}
boolean isColor(Color color) { boolean isColor(Color color) {
return this.color == color; return this.color == color;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment