package dev.kske.chess.board;
/**
* Project: Chess
* File: Position.java
* Created: 02.07.2019
* Author: Kai S. K. Engelbart
*/
public class Position {
public final int x, y;
public Position(int x, int y) {
this.x = x;
this.y = y;
}
public static Position fromSAN(String pos) {
return new Position(pos.charAt(0) - 97, 8 - Character.getNumericValue(pos.charAt(1)));
}
public String toSAN() {
return String.valueOf((char) (x + 97)) + String.valueOf(8 - y);
}
@Override
public String toString() {
return String.format("[%d, %d]", x, y);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Position other = (Position) obj;
if (x != other.x) return false;
if (y != other.y) return false;
return true;
}
}