public boolean queensideClear() { boolean[] flags = ChessGameDemo.getFlags(); int row = square.getRow(); int column = square.getColumn(); if ((row == 1) && (flags[0] || flags[4])) { return false; } if ((row == 8) && (flags[2] || flags[5])) { return false; } if (((row == 1) && (column == 5)) || ((row == 8) && (column == 5))) { for (int i = 1; i < 4; i++) { int r = row; int c = column - i; int cell = square.getCellFromCoord(r, c); Square sq = (Square) board.getComponent(cell); if ((sq.getComponentCount() == 1) || (r < 1)) { return false; } else if (color == 1) { if ((board.getBlackCheckList()).contains(sq.getPosition())) { return false; } } else { if ((board.getWhiteCheckList()).contains(sq.getPosition())) { return false; } } } return true; } return false; }
private void setListForPawn() { moveList.clear(); if (color == 1) { int row = square.getRow(); int column = square.getColumn(); int cell1 = square.getCellFromCoord(row + 1, column); int cell2 = square.getCellFromCoord(row + 2, column); int cell3 = square.getCellFromCoord(row + 1, column + 1); int cell4 = square.getCellFromCoord(row + 1, column - 1); Square s1 = (Square) board.getComponent(cell1); Square s2 = (Square) board.getComponent(cell2); Square s3 = (Square) board.getComponent(cell3); Square s4 = (Square) board.getComponent(cell4); if (s1.getComponentCount() == 0) { moveList.add(s1.getPosition()); squareList.add(s1); } if (s2.getComponentCount() == 0) { moveList.add(s2.getPosition()); squareList.add(s2); } if ((s3.getComponentCount() == 1) && ((Piece) s3.getComponent(0)).getColor() == 0) { moveList.add(s3.getPosition()); squareList.add(s3); } if ((s4.getComponentCount() == 1) && ((Piece) s4.getComponent(0)).getColor() == 0) { moveList.add(s4.getPosition()); squareList.add(s4); } } if (color == 0) { int row = square.getRow(); int column = square.getColumn(); int cell1 = square.getCellFromCoord(row - 1, column); int cell2 = square.getCellFromCoord(row - 2, column); int cell3 = square.getCellFromCoord(row - 1, column + 1); int cell4 = square.getCellFromCoord(row - 1, column - 1); Square s1 = (Square) board.getComponent(cell1); Square s2 = (Square) board.getComponent(cell2); Square s3 = (Square) board.getComponent(cell3); Square s4 = (Square) board.getComponent(cell4); if (s1.getComponentCount() == 0) { moveList.add(s1.getPosition()); squareList.add(s1); } if (s2.getComponentCount() == 0) { moveList.add(s2.getPosition()); squareList.add(s2); } if ((s3.getComponentCount() == 1) && ((Piece) s3.getComponent(0)).getColor() == 1) { moveList.add(s3.getPosition()); squareList.add(s3); } if ((s4.getComponentCount() == 1) && ((Piece) s4.getComponent(0)).getColor() == 1) { moveList.add(s4.getPosition()); squareList.add(s4); } } }
public boolean moveValid(Square candidateSquare) { if (piece == 0) { setListForKing(); } if (piece == 1) { setListForQueen(); } if (piece == 2) { moveList.clear(); setListForRook(); } if (piece == 3) { setListForKnight(); } if (piece == 4) { setListForBishop(); } if (piece == 5) { setListForPawn(); } if (moveList.contains(candidateSquare.getPosition())) { return true; } return false; }
public void handleKeyPress() { if (!running) { return; } Point pos = userSquare.getPosition(); Point newPos = new Point(pos.x + 5, pos.y); positionPusher.updateSquare(userSquare, newPos); }
public void testEmbeddableExplicitAccessStrategy() throws Exception { Square square = new Square(); Position pos = new Position(10, 15); square.setPosition(pos); Session s = openSession(); s.persist(square); Transaction tx = s.beginTransaction(); tx.commit(); s.clear(); tx = s.beginTransaction(); square = (Square) s.get(Square.class, square.getId()); assertEquals(10, square.getPosition().x); try { square.getPosition().getX(); fail(); } catch (RuntimeException e) { // success } s.delete(square); tx.commit(); s.close(); }
public String getLetter() { switch (piece) { case 0: return "K"; case 1: return "Q"; case 2: return "R"; case 3: return "N"; case 4: return "B"; default: return ((square.getPosition()).substring(0, 1)); } }
@Override public void onClick(View v) { Puzzle solution = cont.solvedPuzzle; // Next Move Button if (buttonType == 0) { PuzzleEvent event = cont.getNextHint(); cont.solvedPuzzle.setCurrentEvent(event); if (event == null) { AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); alertDialog.setTitle("Sorry"); alertDialog.setMessage( "There is no more help I can give, but if there is a unique soltuion I do know it (from" + " a quick back tracking search algorithm)"); alertDialog.show(); return; } if (event.isSolveEvent()) { if (cont.showPos) { Button showPos = activity.getShowPosButton(); showPos.performClick(); } for (int i = 0; i < 81; i++) { if (Globals.SHOW_COLOR == cont.puzButtons.getColor(i)) { cont.puzButtons.setColor(i, Globals.SQUARE_COLOR); } } Square solSq = event.getAffectedSquares().get(0); int[] posArr = solSq.getPosition(); int pos = 9 * posArr[0] + posArr[1]; cont.puzButtons.setColor(pos, Globals.SHOW_COLOR); TextView panelBut = cont.panelButtons.getTextView(solSq.value() - 1); panelBut.performClick(); return; } else { for (int i = 0; i < 81; i++) { if (Globals.SHOW_COLOR == cont.puzButtons.getColor(i)) { if (cont.showPos && cont.displayPuzzle.getSquare(i / 9, i % 9).isPossible(cont.numberSet)) { cont.puzButtons.setColor(i, Globals.POSSIBLE_COLOR); } else { cont.puzButtons.setColor(i, Globals.SQUARE_COLOR); } } } if (!cont.delPos) { Button delPos = activity.getDelPosButton(); delPos.performClick(); } List<Square> sqList = event.getAffectedSquares(); List<Integer> nums = event.getNumbers(); for (Square sq : sqList) { int row = sq.getRowNum(); int col = sq.getColNum(); for (int removePos : nums) { if (cont.displayPuzzle.getSquare(row, col).isPossible(removePos)) { cont.puzButtons.setColor((row * 9) + col, Globals.SHOW_COLOR); } } } for (int i : nums) { for (Square solveSq : sqList) { int row = solveSq.getRowNum(); int col = solveSq.getColNum(); Square sq = cont.displayPuzzle.getSquare(row, col); if (sq.isPossible(i)) { TextView panelBut = cont.panelButtons.getTextView(i - 1); panelBut.performClick(); return; } } } return; } } // This means it is the hint button else if (buttonType == 1) { PuzzleEvent event = cont.getNextHint(); cont.solvedPuzzle.setCurrentEvent(event); if (event == null) { AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); alertDialog.setTitle("Sorry"); alertDialog.setMessage( "There is no more help I can give, but if there is a unique soltuion I do know it (from" + " a quick back tracking search algorithm)"); alertDialog.show(); return; } if (event.isSolveEvent()) { for (int i = 0; i < 81; i++) { if (Globals.SHOW_COLOR == cont.puzButtons.getColor(i)) { if (cont.displayPuzzle.getSquare(i / 9, i % 9).isPossible(cont.numberSet) && cont.showPos) { cont.puzButtons.setColor(i, Globals.POSSIBLE_COLOR); } else { cont.puzButtons.setColor(i, Globals.SQUARE_COLOR); } } } Square solSq = event.getAffectedSquares().get(0); int[] posArr = solSq.getPosition(); int pos = 9 * posArr[0] + posArr[1]; cont.puzButtons.setColor(pos, Globals.SHOW_COLOR); return; } else { for (int i = 0; i < 81; i++) { if (Globals.SHOW_COLOR == cont.puzButtons.getColor(i)) { if (cont.showPos && cont.displayPuzzle.getSquare(i / 9, i % 9).isPossible(cont.numberSet)) { cont.puzButtons.setColor(i, Globals.POSSIBLE_COLOR); } else { cont.puzButtons.setColor(i, Globals.SQUARE_COLOR); } } } List<Square> sqList = event.getAffectedSquares(); List<Integer> nums = event.getNumbers(); for (Square sq : sqList) { int row = sq.getRowNum(); int col = sq.getColNum(); for (int removePos : nums) { if (cont.displayPuzzle.getSquare(row, col).isPossible(removePos)) { cont.puzButtons.setColor((row * 9) + col, Globals.SHOW_COLOR); } } } return; } } // possibles button else if (buttonType == 2) { if (cont.showPos == false) { cont.showPos = true; } else { cont.showPos = false; if (cont.delPos == true) { Button delPos = activity.getDelPosButton(); delPos.performClick(); } } int buttonPush = cont.numberSet; bottom.doClick(buttonPush - 1); } // delete possible button else if (buttonType == 3) { if (cont.delPos == false) { cont.delPos = true; cont.showPos = true; c = v.getBackground(); // savedDeleteView = v; v.setBackgroundColor(Globals.DELETE_COLOR); bottom.doClick(cont.numberSet - 1); AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); } else { cont.delPos = false; // v = savedDeleteView; v.setBackground(c); // v.setBackgroundColor(Globals.SQUARE_COLOR); AlertDialog alertDialog = new AlertDialog.Builder(mContext).create(); } } }