#include "StdAfx.h" #include ".\robot.h" #using #include #include "pqueue.h" /* For debugging purposes this method returns the priority of the target robot as the return value. If there is not robot on the queue or the invoking robot is the only robot on the queue, the method return -1. */ int Robot::fight(RobotQueue &pq) { Robot *target; RobotQueue::iterator pos; int i; pos = std::find(pq.begin(), pq.end(), this); if( pos!=pq.end() ){ if( pq.size() == 1 ) return -1; // randomly choose an opponent, but not myself i = rand() % pq.size(); target = pq[i]; if( target == this ) i = (i+1) % pq.size(); } else{ if( pq.size() == 0 ) return -1; i = rand() % pq.size(); } target = pq[i]; target->getHit( rand()%priority ); return target->getPr(); } bool operator<(const Robot &a, const Robot &b) { return a.priority < b.priority; } bool operator>(const Robot &a, const Robot &b) { return a.priority > b.priority; } bool operator<(const PRobot &a, const PRobot &b) { return *a.robot_pointer > *b.robot_pointer; } bool operator>(const PRobot &a, const PRobot &b) { return *a.robot_pointer < *b.robot_pointer; }