This is the Mexican Standoff prototype made by Francisco Martin and Andrew Smith. Please refer to the following link for instructions on hardware hookup: https://developer.mbed.org/users/fomartin/notebook/mexican-standoff-reaction-game/

Dependencies:   SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CPU.cpp Source File

CPU.cpp

00001 #include "States.h"
00002 #include <stdlib.h>
00003 #include <time.h>
00004 #include <float.h>
00005 
00006     
00007 
00008 CPU::CPU()
00009 {
00010     difficulty = 1; 
00011     srand(time(NULL));
00012 }
00013 
00014 CPU::CPU(int cpu_difficulty)
00015 {
00016     difficulty = cpu_difficulty;
00017     srand(time(NULL));
00018 }
00019 
00020 float CPU::shootTime()
00021 {
00022     
00023     int randNumber = rand() % 10;
00024 
00025     float answer = (rand() % 10 + 1) / 10.0f;
00026     return answer / (float) difficulty;       
00027 }
00028 
00029 bool CPU::shootAnswer(Prompt correctAnswer)
00030 {   
00031     if(correctAnswer == Down || correctAnswer == Up)
00032     {
00033         int randNumber = rand() % 10;
00034 
00035         if(randNumber == 9)
00036             return false;
00037     }
00038     
00039     return true;     
00040 }