!752 static class XY { int x, y; // 1-8 (a-h), 1-8 *(int *x, int *y) {} *() {} public boolean equals(O o) { //ret stdEq(this, o, "x", "y"); if (!(o instanceof XY)) ret false; XY xy = cast o; ret x == xy.x && y == xy.y; } boolean valid() { ret x >= 1 && x <= 8 && y >= 1 && y <= 8; } public S toString() { ret (char) ('a'+x-1) + "" + y; } } static XY pos(S s) { assertEquals(2, l(s)); ret new XY(toLower(s.charAt(0))-'a'+1, s.charAt(1)-'1'+1); } p { makeBot("Chess Bot!"); } answer { if "if the * is on *, where can it move?" { S piece = m.unq(0), pos = m.unq(1); try { ret structure(allToString(destPlaces(piece, pos(pos)))); } catch (Exception e) { ret str(e); } } } static Map movementTable = litmap( "king", new int[] {-1, -1, 0, -1, 1, -1, -1, 0, 1, 0, -1, 1, 0, 1, 1, 1}, "queen", new int[] {-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, -1, 0, -2, 0, -3, 0, -4, 0, -5, 0, -6, 0, -7, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, -1, 0, -2, 0, -3, 0, -4, 0, -5, 0, -6, 0, -7}, "knight", new int[] {-1, -2, -2, -1, 1, -2, 2, -1, 1, 2, 2, 1, -1, 2, -2, 1}, "rook", new int[] {1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, -1, 0, -2, 0, -3, 0, -4, 0, -5, 0, -6, 0, -7, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, -1, 0, -2, 0, -3, 0, -4, 0, -5, 0, -6, 0, -7}, "bishop", new int[] {-1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6, -7, -7, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7}, ); static L destPlaces(S piece, XY pos) { int[] m = movementTable.get(piece.toLowerCase()); if (m != null) ret movements(pos, m); throw fail("What is a *", piece); } static L movements(XY pos, int... bla) { new L l; for (int i = 0; i < l(bla); i += 2) addIfValid(l, new XY(pos.x + bla[i], pos.y + bla[i+1])); ret l; } static void addIfValid(L l, XY xy) { if (xy.valid()) l.add(xy); }