Exemple #1
0
//================================
//MOVE
//================================
void Match::moveUp(Player *p)
{
   // cout << " Moves Forward" << endl;

    if(p->getStatus() == p->BALL_WITH_OPP)
    {
        dodge(p);
    }
    else
    {
        int team = p->getTeam();
        if(team == 1)
        {
            p->setPosX(p->getPosX() + 1);
        }
        else if(team == 2)
        {
            p->setPosX(p->getPosX() - 1);
        }
        checkBall(p);
        if(p->getNumber() == ball->getPlayer())
        {
            updateBall(p);
            screen->updateMove(p, p->MOVE_UP);
        }
    }

    checkWin(p);
}
Exemple #2
0
void MainLogicLoop(){
		//TODO lock the camera
		//lockCamera(&processHandle);

		//read the data at these pointers, now that offsets have been added and we have a static address
        ReadPlayer(&Enemy, processHandle, EnemyId);
        ReadPlayer(&Player, processHandle, PlayerId);

        //log distance in memory
        AppendDistance(distance(&Player, &Enemy));

        //start the neural network threads
        WakeThread(defense_mind_input);
        WakeThread(attack_mind_input);

        ResetVJoyController();

		//begin reading enemy state, and handle w logic and subroutines
        char attackImminent = EnemyStateProcessing(&Player, &Enemy);

        WaitForThread(defense_mind_input);
        guiPrint(LocationDetection",1:Defense Neural Network detected %d, and Attack %d", DefenseChoice, AttackChoice);
#if DebuggingPacifyDef
        DefenseChoice = 0;
#endif
		//defense mind makes choice to defend or not(ex backstab metagame decisions).
		//handles actually backstab checks, plus looks at info from obveous direct attacks from aboutToBeHit
        if (attackImminent == ImminentHit || inActiveDodgeSubroutine() || (DefenseChoice>0)){
            dodge(&Player, &Enemy, &iReport, attackImminent, DefenseChoice);
		}

        WaitForThread(attack_mind_input);
        guiPrint(LocationDetection",2:Attack Neural Network decided %d", AttackChoice);
#if DebuggingPacifyAtk
        AttackChoice = 0;
#endif
		//attack mind make choice about IF to attack or not, and how to attack
        //enter when we either have a Attack neural net action or a attackImminent action
        if (inActiveAttackSubroutine() || attackImminent != ImminentHit || (AttackChoice && DefenseChoice<=0)){
            attack(&Player, &Enemy, &iReport, attackImminent, AttackChoice);
        }

        //unset neural network desisions
        DefenseChoice = 0;
        AttackChoice = 0;
        //handle subroutine safe exits
        SafelyExitSubroutines();

        guiPrint(LocationDetection",5:Current Subroutine States ={%d,%d,%d,%d}", subroutine_states[0], subroutine_states[1], subroutine_states[2], subroutine_states[3]);

		//send this struct to the driver (only 1 call for setting all controls, much faster)
        guiPrint(LocationJoystick",0:AxisX:%d\nAxisY:%d\nButtons:0x%x", iReport.wAxisX, iReport.wAxisY, iReport.lButtons);
		UpdateVJD(iInterface, (PVOID)&iReport);

		//SetForegroundWindow(h);
		//SetFocus(h);
}
Exemple #3
0
int monster::dodge_roll()
{
 int numdice = dodge();

 switch (type->size) {
  case MS_TINY:  numdice += 6; break;
  case MS_SMALL: numdice += 3; break;
  case MS_LARGE: numdice -= 2; break;
  case MS_HUGE:  numdice -= 4; break;
 }

 numdice += int(speed / 80);
 return dice(numdice, 10);
}
Exemple #4
0
int player::dodge_roll()
{
 return dice(dodge(), 6);
}
Exemple #5
0
int player::dodge_roll(game *g)
{
 return dice(dodge(g), 6);
}
Exemple #6
0
int player::dodge_roll(game *g)
{
    return dice(dodge(g), 10); //Matches NPC and monster dodge_roll functions
}
Exemple #7
0
int main(int argc, char** argv) {
    if (argc < 5) {
        printf("Usage: %s <ball_position_x> <ball_position_y> <finish_position_x> <finish_position_y>\n", argv[0]);
        return EXIT_FAILURE;
    }

    int WAITED = 0;
    int BALL_X = atoi(argv[1]);
    int BALL_Y = atoi(argv[2]);
    int FINISH_X = atoi(argv[3]);
    int FINISH_Y = atoi(argv[4]);
    int START = 0;
    int RANK, SIZE, PREV, NEXT;

    status robot_status;
    robot_status.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    state robot_state;
    robot_state.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    distance robot_dist;
    robot_dist.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    color robot_color;
    robot_color.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    angle robot_angle;
    robot_angle.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    plier robot_plier;
    robot_plier.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
    position robot_position;
    robot_position.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;

    struct state_arguments *arg = malloc(sizeof(struct state_arguments));

    arg->robot_state = robot_state;
    arg->robot_dist = robot_dist;
    arg->robot_color = robot_color;
    arg->robot_plier = robot_plier;

    pthread_t thread_dist, thread_color, thread_angle, thread_plier, thread_state;
    if(pthread_create(&thread_dist, NULL, update_dist, NULL) == -1) {
        perror("Creation of thread thread_dist failed !");
        return EXIT_FAILURE;
    }
    if(pthread_create(&thread_color, NULL, update_color, NULL) == -1) {
        perror("Creation of thread thread_color failed !");
        return EXIT_FAILURE;
    }
    if(pthread_create(&thread_angle, NULL, update_angle, NULL) == -1) {
        perror("Creation of thread thread_angle failed !");
        return EXIT_FAILURE;
    }
    if(pthread_create(&thread_plier, NULL, update_plier, NULL) == -1) {
        perror("Creation of thread thread_plier failed !");
        return EXIT_FAILURE;
    }
    if(pthread_create(&thread_state, NULL, update_state, arg) == -1) {
        perror("Creation of thread thread_state failed !");
        return EXIT_FAILURE;
    }

    while(1) {
        if (START == 0) {
            bluetooth msg = recuperer_msg();
            if (msg && msg.type == 3) { // START msg
                RANK = msg.rank;
                SIZE = msg.size;
                PREV = msg.prev;
                NEXT = msg.next;
                START = 1;
                pthread_mutex_lock(&robot_status.mutex);
                robot_status.status = PREV == 0xFF ? LEADER : FOLLOWER;
                pthread_mutex_unlock(&robot_status.mutex);
            } else {
                continue;
            }
        }

        bluetooth_msg = recuperer_msg();
        if (msg && msg.type == 4) { // STOP msg
            START = 0;
            continue;
        } else if(msg && msg.type == 7) { // KICK msg
            if ((RANK - 1) == msg.rank) {
                PREV = msg.prev;
            } else if ((RANK + 1) == msg.rank) {
                NEXT = msg.next
            } else if (RANK = msg.rank) {
                START = 0;
                continue;
            }
        }

        pthread_mutex_lock(&robot_status.mutex);
        if (robot_status.status == LEADER) {
            pthread_mutex_lock(&robot_state.mutex);
            pthread_mutex_unlock(&robot_status.mutex);

            switch(robot_state.state) {
            case FREE:
                WAITED = 0;
                pthread_mutex_lock(&robot_position.mutex);
                pthread_mutex_lock(&robot_angle.mutex);

                if ((robot_position.y != BALL_Y) && (robot_angle.angle != 0)) {
                    moteur_tourner(-1 * sign(robot_angle.angle) * min(5, abs(robot_angle.angle)));
                } else if(robot_position.y != BALL_Y) {
                    moteur_avancer(0,sign(BALL_Y - robot_position.y) * 2);
                } else if((robot_position.x != BALL_X) && (abs(robot_angle.angle) != 90)) {
                    moteur_tourner(sign(BALL_X) * min(5, abs(robot_angle.angle)));
                } else {
                    moteur_avancer(sign(BALL_X - robot_position.x) *2, 0);
                }
                pthread_mutex_unlock(&robot_position.mutex);
                pthread_mutex_unlock(&robot_angle.mutex);
                break;

            case STOP:
                if (WAITED > 20) {
                    WAITED = 0;
                    pthread_mutex_lock(&robot_position.mutex);
                    pthread_mutex_lock(&robot_angle.mutex);
                    dodge(robot_position, robot_angle, BALL_X, BALL_Y); //TODO
                    pthread_mutex_unlock(&robot_position.mutex);
                    pthread_mutex_unlock(&robot_angle.mutex);
                } else {
                    sleep(1);
                    WAITED += 1;
                }
                break;

            case GRAB:
                //prendre_balle(); //TODO
                break;

            case PRE_GRAB:
                pthread_mutex_lock(&robot_position.mutex);
                if (robot_position.y != BALL_Y) {
                    moteur_avancer(0, sign(BALL_Y - robot_position.y) * 2);
                } else {
                    moteur_avancer(sign(BALL_X - robot_postition.x) * 2, 0);
                }
                pthread_mutex_unlock(&robot_position.mutex);
                break;

            case GRABBED_FREE:
                WAITED = 0;
                pthread_mutex_lock(&robot_position.mutex);
                pthread_mutex_lock(&robot_angle.mutex);

                if ((robot_position.y != FINISH_Y) && (robot_angle.angle != 0)) {
                    moteur_tourner(-1 * sign(robot_angle.angle) * min(5, abs(robot_angle.angle)));
                } else if(robot_position.y != FINISH_Y) {
                    moteur_avancer(0, sign(FINISH_Y - robot_position.y) * 2);
                } else if((robot_position.x != FINISH_X) && (abs(robot_angle.angle) != 90)) {
                    moteur_tourner(sign(FINISH_X) * min(5, abs(robot_angle.angle)));
                } else {
                    moteur_avancer(sign(FINISH_X - robot_position.x) * 2, 0);
                }
                pthread_mutex_unlock(&robot_position.mutex);
                pthread_mutex_unlock(&robot_angle.mutex);
                break;

            case GRABBED_STOP:
                if (WAITED > 20) {
                    WAITED = 0;
                    pthread_mutex_lock(&robot_position.mutex);
                    pthread_mutex_lock(&robot_angle.mutex);
                    dodge(robot_position, robot_angle, BALL_X, BALL_Y); //TODO
                    pthread_mutex_unlock(&robot_position.mutex);
                    pthread_mutex_unlock(&robot_angle.mutex);
                } else {
                    sleep(1);
                    WAITED += 1;
                }
                break;

            default:
                printf("Ohoh something went wrong ! The Robot has an undefined state :(\n");
            }

            pthread_mutex_unlock(&robot_state.mutex);
        } else if (robot_status.status == FOLLOWER) {
            bluetooth msg = recuperer_msg();
            if (msg) {
                switch (msg.type) {
                case 0: // ACTION msg
                    pthread_mutex_lock(&robot_position.mutex);
                    moteur_avancer(robot_position.x + msg.dist * sin(to_radians(msg.angle)), robot_position.y + msg.dist * cos(to_radians(msg.angle)));
                    pthread_mutex_unlock(&robot_position.mutex);
                    break;
                case 2: // LEAD msg
                    sleep(15);
                    //play_zelda();
                    robot_status.status = LEADER;
                    break;
                case 5: // WAIT msg
                    moteur_stop();
                    sleep(msg.delay);
                    break;
                default:
                    printf("Just received a useless message !");
                }
            }
        } else {
            perror("Unknown robot status !");
            return EXIT_FAILURE;
        }
        pthread_mutex_unlock(&robot_status.mutex);
    }

    return EXIT_SUCCESS;
}