/*Wrapper function, adds legal Pawn Moves from Location to Linked List*/ int getPawnMoves(Game *game, Location *loc, ListNode *temp){ int flag = 0; if (canMoveUK(game->board, loc, 1) && isEmpty(game->board[loc->column][loc->row + shiftUp(game->board, loc)])){ Move *move = setMove(loc, setLocation(loc->column, loc->row + shiftUp(game->board, loc)), NONETYPE); if (isValidMove(game, move)){ getPawnSingleMove(game->board, loc, temp, move); flag = 1; } else{ freeMove(move); } } if (canMoveULK(game->board, loc, 1) && isOpposite(game->board[loc->column + shiftLeft(game->board, loc)][loc->row + shiftUp(game->board, loc)], game->board, loc)){ Move *move = setMove(loc, setLocation(loc->column + shiftLeft(game->board, loc), loc->row + shiftUp(game->board, loc)), NONETYPE); if (isValidMove(game, move)){ getPawnSingleMove(game->board, loc, temp, move); flag = 1; } else{ freeMove(move); } } if (canMoveURK(game->board, loc, 1) && isOpposite(game->board[loc->column + shiftRight(game->board, loc)][loc->row + shiftUp(game->board, loc)], game->board, loc)){ Move *move = setMove(loc, setLocation(loc->column + shiftRight(game->board, loc), loc->row + shiftUp(game->board, loc)), NONETYPE); if (isValidMove(game, move)){ getPawnSingleMove(game->board, loc, temp, move); flag = 1; } else{ freeMove(move); } } return flag; }
/*Add legal Moves for Knight at Location to Linked List*/ int getKnightSingleMove(Game *game, Location *loc, ListNode *temp, MoveType type){ MoveType col; MoveType row; char c; int flag = 0; switch (type) { case UR:col = R; row = U; break; case UL:col = L; row = U; break; case DL:col = L; row = D; break; case DR:col = R; row = D; break; case U:row = U; case D:row = D; case L:col = L; case R:row = R; } if (canMoveK(game->board, loc, 1, col) && canMoveK(game->board, loc, 2, row)){ c = game->board[loc->column + shiftCol(game->board, loc, col)][loc->row + shiftRow(game->board, loc, row) * 2]; if (isEmpty(c) || isOpposite(c, game->board, loc)){ Move *move = setMove(loc, setLocation(loc->column + shiftCol(game->board, loc, col), loc->row + shiftRow(game->board, loc, row) * 2), NONETYPE); if (isValidMove(game, move)){ addMoveToList(temp, move); flag = 1; } else{ freeMove(move); } } } if (canMoveK(game->board, loc, 2, col) && canMoveK(game->board, loc, 1, row)){ c = game->board[loc->column + shiftCol(game->board, loc, col) * 2][loc->row + shiftRow(game->board, loc, row)]; if (isEmpty(c) || isOpposite(c, game->board, loc)){ Move *move = setMove(loc, setLocation(loc->column + shiftCol(game->board, loc, col) * 2, loc->row + shiftRow(game->board, loc, row)), NONETYPE); if (isValidMove(game, move)){ addMoveToList(temp, move); flag = 1; } else{ freeMove(move); } } } return flag; }
void Snake::changeDir(sDir dir) { // dir - which button is pressed // this->dir - current direction if (isOpposite(dir, this->dir)) { return; } else { this->dir = dir; } }
char JudgeDredd::takeAPiece(GameInfo& game, coord_t& coord) { char count = 0; if (coord.y > 2 && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y - 1][coord.x]) == true && CHECKMASK(game.getMap()[coord.y - 1][coord.x], TAKENMASKH) == true) count++, game.takeOffPieceOnBoard(coord.y - 1, coord.x, NORTH); if (coord.y + 3 < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y + 1][coord.x]) == true && CHECKMASK(game.getMap()[coord.y + 1][coord.x], TAKENMASKH) == true) count++, game.takeOffPieceOnBoard(coord.y + 1, coord.x, SOUTH); if (coord.x > 2 && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y][coord.x - 1]) == true && CHECKMASK(game.getMap()[coord.y][coord.x - 1], TAKENMASKV) == true) count++, game.takeOffPieceOnBoard(coord.y, coord.x - 1, WEST); if (coord.x + 3 < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y][coord.x + 1]) == true && CHECKMASK(game.getMap()[coord.y][coord.x + 1], TAKENMASKV) == true) count++, game.takeOffPieceOnBoard(coord.y, coord.x + 1, EAST); if (coord.x > 2 && coord.y > 2 && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y - 1 ][coord.x - 1]) && CHECKMASK(game.getMap()[coord.y - 1][coord.x - 1], TAKENMASKDNS) == true) count++, game.takeOffPieceOnBoard(coord.y - 1, coord.x - 1, NORTHWEST); if (coord.x + 3 < LENGTHBOARD && coord.y + 3 < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y + 1 ][coord.x + 1]) && CHECKMASK(game.getMap()[coord.y + 1][coord.x + 1], TAKENMASKDNS) == true) count++, game.takeOffPieceOnBoard(coord.y + 1, coord.x + 1, SOUTHEAST); if (coord.x > 2 && coord.y + 3 < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y + 1 ][coord.x - 1]) && CHECKMASK(game.getMap()[coord.y + 1][coord.x - 1], TAKENMASKDNS) == true) count++, game.takeOffPieceOnBoard(coord.y + 1, coord.x - 1, SOUTHWEST); if (coord.x + 3 < LENGTHBOARD && coord.y > 2 && isOpposite(game.getCurrentPlayer(), game.getMap()[coord.y - 1 ][coord.x + 1]) && CHECKMASK(game.getMap()[coord.y - 1][coord.x + 1], TAKENMASKDNS) == true) count++, game.takeOffPieceOnBoard(coord.y - 1, coord.x + 1, NORTHEAST); return count; }
void JudgeDredd::lookAlignement(GameInfo& game, coord_t& coord) { int count; int stop = 0; int** tmp = game.getMap(); int n[4]; n[0] = 0; n[1] = 0; n[2] = 0; n[3] = 0; if (CHECKMASK(tmp[coord.y][coord.x], CPH) != true) stop |= (1 | 2); if (CHECKMASK(tmp[coord.y][coord.x], CPV) != true) stop |= (4 | 8); if (CHECKMASK(tmp[coord.y][coord.x], CPDNS) != true) stop |= (16 | 32); if (CHECKMASK(tmp[coord.y][coord.x], CPDSN) != true) stop |= (64 | 128); for (count = 0; count < LENGTHBOARD && stop < 255; count++) { if (CHECKMASK(stop, 1) != true) { if (coord.y - count > 0 && isOpposite(game.getCurrentPlayer(), tmp[coord.y - count][coord.x]) != true) stop |= checkTaken(tmp[coord.y - count][coord.x], NORTH); else stop |= 1; if (CHECKMASK(stop, 1) != true) n[0]++; } if (CHECKMASK(stop, 2) != true) { if (coord.y + count < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), tmp[coord.y + count][coord.x]) != true) stop |= checkTaken(tmp[coord.y + count][coord.x], SOUTH); else stop |= 2; if (CHECKMASK(stop, 2) != true) n[0]++; } if (CHECKMASK(stop, 4) != true) { if (coord.x - count > 0 && isOpposite(game.getCurrentPlayer(), tmp[coord.y][coord.x - count]) != true) stop |= checkTaken(tmp[coord.y][coord.x - count], WEST); else stop |= 4; if (CHECKMASK(stop, 4) != true) n[1]++; } if (CHECKMASK(stop, 8) != true) { if (coord.x + count < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), tmp[coord.y][coord.x + count]) != true) stop |= checkTaken(tmp[coord.y][coord.x + count], EAST); else stop |= 8; if (CHECKMASK(stop, 8) != true) n[1]++; } if (CHECKMASK(stop, 16) != true) { if (coord.x - count > 0 && coord.y - count > 0 && isOpposite(game.getCurrentPlayer(), tmp[coord.y - count][coord.x - count]) != true) stop |= checkTaken(tmp[coord.y - count][coord.x - count], NORTHWEST); else stop |= 16; if (CHECKMASK(stop, 16) != true) n[2]++; } if (CHECKMASK(stop, 32) != true) { if (coord.x + count < LENGTHBOARD && coord.y + count < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), tmp[coord.y + count][coord.x + count]) != true) stop |= checkTaken(tmp[coord.y + count][coord.x + count], SOUTHEAST); else stop |= 32; if (CHECKMASK(stop, 32) != true) n[2]++; } if (CHECKMASK(stop, 64) != true) { if (coord.x + count > LENGTHBOARD && coord.y - count > 0 && isOpposite(game.getCurrentPlayer(), tmp[coord.y - count][coord.x + count]) != true) stop |= checkTaken(tmp[coord.y - count][coord.x + count], NORTHEAST); else stop |= 64; if (CHECKMASK(stop, 64) != true) n[3]++; } if (CHECKMASK(stop, 128) != true) { if (coord.x - count < 0 && coord.y + count < LENGTHBOARD && isOpposite(game.getCurrentPlayer(), tmp[coord.y + count][coord.x - count]) != true) stop |= checkTaken(tmp[coord.y + count][coord.x - count], SOUTHWEST); else stop |= 128; if (CHECKMASK(stop, 128) != true) n[3]++; } if (n[0] >= 5 || n[1] >= 5 || n[2] >= 5 || n[3] >= 5) { //GameExceptionWinByAlignement& exc = GameExceptionWinByAlignement(); GameExceptionWinByAlignement exc = GameExceptionWinByAlignement(); throw exc; } } }