Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CheckersLineCast(original_row, original_column, new_row_direction, new_column_direction)
- {
- MoveSet = [];
- grid = level.checkers_grid;
- cur_row = original_row;
- cur_column = original_column;
- cur_row_direction = new_row_direction;
- cur_column_direction = new_column_direction;
- set_piece = grid[original_row][original_column].object;
- keepGoing = true;
- while(keepGoing)
- {
- newRow = cur_row + cur_row_direction;
- newColumn = cur_column + cur_column_direction;
- if (!isDefined(grid[newRow]))
- keepGoing = false;
- if (!isDefined(grid[newRow][newColumn]))
- keepGoing = false;
- if (!keepGoing)
- break;
- if (GridPointEmpty(newRow, newColumn) && MoveSet.size < 1)
- {
- MoveSet[MoveSet.size] = grid[newRow][newColumn];
- keepGoing = false;
- break;
- }
- else
- {
- if (isDefined(grid[newRow]))
- {
- if (isDefined(grid[newRow][newColumn]))
- {
- if (MoveExists(MoveSet, newRow + cur_row_direction, newColumn + cur_column_direction))
- {
- keepGoing = false;
- break;
- }
- if (canJump(set_piece, newRow, newColumn, cur_row_direction, cur_column_direction))
- {
- MoveSet[MoveSet.size] = grid[newRow + cur_row_direction][newColumn + cur_column_direction]; //add +1 for jumping
- cur_row = newRow + cur_row_direction;
- cur_column = newColumn + cur_column_direction;
- maxCol = level.num_of_columns - 1;
- maxRow = level.num_of_rows - 1;
- if ((cur_row == 0 && cur_column == 0) || (cur_row == 0 && cur_column == maxCol) || (cur_row == maxRow && cur_column == 0) || (cur_row == maxRow && cur_column == maxCol))
- {
- //in case pawn reaches a corner
- keepGoing = false;
- break;
- }
- else
- {
- //if pawn reaches first/last col/row, reverse direction
- if (cur_row == 0)
- cur_row_direction = 1;
- else if (cur_row == maxRow)
- cur_row_direction = -1;
- if (cur_column == 0)
- cur_column_direction = 1;
- else if (cur_column == maxCol)
- cur_column_direction = -1;
- }
- }
- else { keepGoing = false; break; }
- }
- else { keepGoing = false; break; }
- }
- else { keepGoing = false; break; }
- }
- }
- return MoveSet;
- }
Advertisement
Add Comment
Please, Sign In to add comment