Im_YouViolateMe

CheckersLineCast function

Apr 2nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. CheckersLineCast(original_row, original_column, new_row_direction, new_column_direction)
  2. {
  3.     MoveSet = [];
  4.    
  5.     grid = level.checkers_grid;
  6.     cur_row = original_row;
  7.     cur_column = original_column;
  8.     cur_row_direction = new_row_direction;
  9.     cur_column_direction = new_column_direction;
  10.     set_piece = grid[original_row][original_column].object;
  11.     keepGoing = true;
  12.    
  13.     while(keepGoing)
  14.     {
  15.         newRow = cur_row + cur_row_direction;
  16.         newColumn = cur_column + cur_column_direction;
  17.        
  18.         if (!isDefined(grid[newRow]))
  19.             keepGoing = false;
  20.         if (!isDefined(grid[newRow][newColumn]))
  21.             keepGoing = false;
  22.        
  23.         if (!keepGoing)
  24.             break;
  25.        
  26.         if (GridPointEmpty(newRow, newColumn) && MoveSet.size < 1)
  27.         {
  28.             MoveSet[MoveSet.size] = grid[newRow][newColumn];
  29.             keepGoing = false;
  30.             break;
  31.         }
  32.         else
  33.         {
  34.             if (isDefined(grid[newRow]))
  35.             {
  36.                 if (isDefined(grid[newRow][newColumn]))
  37.                 {
  38.                     if (MoveExists(MoveSet, newRow + cur_row_direction, newColumn + cur_column_direction))
  39.                     {
  40.                         keepGoing = false;
  41.                         break;
  42.                     }
  43.                    
  44.                     if (canJump(set_piece, newRow, newColumn, cur_row_direction, cur_column_direction))
  45.                     {
  46.                         MoveSet[MoveSet.size] = grid[newRow + cur_row_direction][newColumn + cur_column_direction]; //add +1 for jumping
  47.                         cur_row = newRow + cur_row_direction;
  48.                         cur_column = newColumn + cur_column_direction;
  49.                        
  50.                         maxCol = level.num_of_columns - 1;
  51.                         maxRow = level.num_of_rows - 1;
  52.                        
  53.                         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))
  54.                         {
  55.                             //in case pawn reaches a corner
  56.                             keepGoing = false;
  57.                             break;
  58.                         }
  59.                         else
  60.                         {
  61.                             //if pawn reaches first/last col/row, reverse direction
  62.                             if (cur_row == 0)
  63.                                 cur_row_direction = 1;
  64.                             else if (cur_row == maxRow)
  65.                                 cur_row_direction = -1;
  66.                            
  67.                             if (cur_column == 0)
  68.                                 cur_column_direction = 1;
  69.                             else if (cur_column == maxCol)
  70.                                 cur_column_direction = -1;
  71.                         }
  72.                     }
  73.                     else { keepGoing = false; break; }
  74.                 }
  75.                 else { keepGoing = false; break; }
  76.             }
  77.             else { keepGoing = false; break; }
  78.         }
  79.     }
  80.    
  81.     return MoveSet;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment