Пример #1
0
   void displayCall(){
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  drawBoard(11);  
  
  int x, y; char owner;
  while(true){
     cout<<"Enter (row) [space] (column)"<<endl;
     cout<<"Ex: 1 11 or 11 5"<<endl;
     cin>>x>>y;
     if(x>0 && x<=11 && y>0 && y<=11 && hexBoard.getVector()[x-1][y-1].owner == '-'){
        owner = 'R'; 
        break;
     }
  }
  x--; y--; //used for translating input of 1-11 to data of 0-10
  hexBoard.placePiece(x, y, owner);
  posNode temp = posNode(x,y,owner);
  board.push_back(temp);

  for(auto element: board)
     colorHex(element.coordX, element.coordY, element.owner);

  drawBoard(11);
  drawRects();
 
  glutSwapBuffers();
  char winner = ' ';
  determineWinner(connectivityMatrix, hexBoard, boardWidth, winner, false);
  if(winner == 'R') exit(0);
}
Пример #2
0
Файл: hex.cpp Проект: Bwichs/HEX
 //Used to determine winner of HEX and print to screen
   void determineWinner(graph& test1, board& board1, int bWidth, char & winner, 
                        bool AIdeciding){
      int redWinner = 0;  //determine if there is a winning distance from left to right
      int blueWinner = 0; //determine in there is a winning distance from top to bottom
      int topRow = bWidth;    //used to iterate through top row of board
      int posTopRow = 0;                  //keep track of top row position
      int posLeftCol = 0;

    //while there is no path from current top to bottom position and there are more top
    //  positions to check against the bottom row
      while(blueWinner == 0 && redWinner == 0 && topRow > 0){ 
       //while there is no path from current top to bottom position and there are more
       //  bottom positions to check against the current top position
          //quick dijkstra's to determine if there is a winning path
            redWinner = dijkstra(posTopRow, 
                     test1.getSize(), test1.getVector(), board1.getVector(), 1);
            blueWinner = dijkstra(posLeftCol,
                     test1.getSize(), test1.getVector(), board1.getVector(), 0);
         topRow--;
         posTopRow++;
         posLeftCol+=bWidth;
      }

      if(!AIdeciding){
         if(blueWinner != 0){ 
            winner = 'B';
            cout<<"WINNER IS BLUE!"<<endl;
         }
         else if(redWinner != 0){
            winner = 'R';
            cout << "WINNER IS RED!"<<endl;
         }
      }
      else{
         if(blueWinner != 0)
            winner = 'B';
         else if(redWinner != 0)
            winner = 'R';
      }

   }