public override Tuple<uint, uint, uint, uint> getInput(Board B, string inp) { uint xFrom = (uint)inp[0]-48; uint yFrom = (uint)inp[1]-48; uint xTo = (uint)inp[2]-48; uint yTo = (uint)inp[3]-48; return new Tuple<uint, uint, uint, uint>(xFrom, yFrom, xTo, yTo); }
//Checks if move is possible public bool movePossible(uint x, uint y, Board.QueryFunc QF) { List<Tuple<uint, uint>> tmp; tmp = this.getPossibleMoves(QF); foreach (Tuple<uint, uint> item in tmp) { if ((item.Item1 == x) && (item.Item2 == 2)) { return true; } } return false; }
public override List<Tuple<uint, uint>> getPossibleMoves(Board.QueryFunc QF) { List<Tuple<uint, uint>> moves = new List<Tuple<uint, uint>>(); // Check down moves int x = (int)getX(); int y = (int)getY(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { int nx = x + i; int ny = y + j; if (withinBoard(nx, ny)) { Square s = QF((uint) nx, (uint) ny); if((getColour() == "white" && s.getBlackCover() == 0) || (getColour() == "black" && s.getWhiteCover() == 0)) { Piece p = s.getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)nx, (uint)ny)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)nx, (uint)ny)); } } } } } } // Done, all moves found return moves; }
//returns a list of all possible moves public abstract List<Tuple<uint, uint>> getPossibleMoves(Board.QueryFunc QF);
public void start(string p1, string p2) { turnWhite = true; board = new Board(); newInput = ""; if (p1 == "TA") { white = new TerminalAgent("white"); } put(p1); if (p2 == "TA") { black = new TerminalAgent("black"); } put(p2); printBoard(); run(); run(); }
public override List<Tuple<uint, uint>> getPossibleMoves(Board.QueryFunc QF) { List<Tuple<uint, uint>> moves = new List<Tuple<uint, uint>>(); // Check down, left moves int x = (int)getX(); int y = (int)getY(); while (true) { x--; y--; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check down, right moves x = (int)getX(); y = (int)getY(); while (true) { x++; y--; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check up, right moves x = (int)getX(); y = (int)getY(); while (true) { x++; y++; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check left, up moves x = (int)getX(); y = (int)getY(); while (true) { x--; y++; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check down moves x = (int) getX(); y = (int) getY(); while(true) { y--; if (!withinBoard(x,y)) { break; } Piece p = QF((uint) x, (uint) y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint) x, (uint) y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check up moves x = (int) getX(); y = (int) getY(); while (true) { y++; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check right moves x = (int) getX(); y = (int) getY(); while (true) { x++; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Check left moves x = (int) getX(); y = (int) getY(); while (true) { x--; if (!withinBoard(x, y)) { break; } Piece p = QF((uint)x, (uint)y).getPiece(); if (p == null) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); } else { if (p.getColour() != getColour()) { moves.Add(new Tuple<uint, uint>((uint)x, (uint)y)); break; } else { break; } } } // Done, all moves found return moves; }
//Promts the agent to make a move public abstract Tuple<uint, uint, uint, uint> getInput(Board B, string inp);
public override List<Tuple<uint, uint>> getPossibleMoves(Board.QueryFunc QF) { List<Tuple<uint, uint>> tmpList = new List<Tuple<uint, uint>>(); short yMod; if (this.colour == "white") yMod = 1; else yMod = -1; // Take left if (withinBoard((int)getX() - 1, (int)getY() + yMod)) { Square S = QF((uint)(getX() - 1), (uint)(getY() + yMod)); Piece P = S.getPiece(); if (P != null) { if (!isSameColour(P)) { tmpList.Add(new Tuple<uint, uint>((uint)(getX() - 1), (uint)(getY() + yMod))); } } } //Take right if (withinBoard((int)getX() + 1, (int)getY() + yMod)) { Square S = QF((uint)(getX() + 1), (uint)(getY() + yMod)); Piece P = S.getPiece(); if (P != null) { if (!isSameColour(P)) { tmpList.Add(new Tuple<uint, uint>((uint)(getX() + 1), (uint)(getY() + yMod))); } } } //Move 1 if (withinBoard((int)getX(), (int)getY() + yMod)) { Square S = QF(getX(), (uint)(getY() + yMod)); Piece P = S.getPiece(); if (P == null) { tmpList.Add(new Tuple<uint, uint>(getX(), (uint)(getY() + yMod))); } } //Move 2 (Only first move) if (!movedFromInit()) { if (withinBoard((int)getX(), (int)getY() + 2 * yMod)) { Square S = QF(getX(), (uint)(getY() + 2 * yMod)); Piece P = S.getPiece(); if (P == null) { tmpList.Add(new Tuple<uint, uint>(getX(), (uint)(getY() + 2 * yMod))); } } } return tmpList; }