AlezM

Spatial Games

Feb 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. enum PlayerType { D, C };
  8.  
  9. class Cell {
  10. public:
  11.   PlayerType type;
  12.   double score;
  13.   Cell () : type(C), score(0) {};
  14.   Cell (PlayerType _type) : type(_type), score(0) {};
  15.  
  16.   double InterractWith (Cell member) {
  17.     if (member.type == C) {
  18.       if (type == C)
  19.         score += 1;
  20.       else
  21.         score += 1.8;
  22.     }
  23.   }
  24. };
  25. // x = ( (i + x) + size ) % size
  26. // y = ( ((i/size) + y) + size ) % size
  27.  
  28. void CalculateScores (vector<Cell> grid) {
  29.   int size = sqrt(grid.size());
  30.   for (int i = 0; i < grid.size(); i++) {
  31.     for (int x = -1; x < 2; x++) {
  32.       for (int y = -1; y < 2; y++) {
  33.         int memberX = ( (i + x) + size ) % size;
  34.         int memberY = ( ((i/size) + y) + size ) % size;
  35.        
  36.         grid.at(i).IntarractWith( grid.at(memberX + memberY*size) );
  37.       }
  38.     }
  39.   }
  40. }
Add Comment
Please, Sign In to add comment