# C++ text based football — lookup table and AI logic help

I am trying to develop a one-player text based football game in C++ strictly in the console without graphics. I am developing the game logic here below vs the CPU and I also need to do the vice versa (CPU vs User). How could I do this without a ton of if statements. I am not sure how to accomplish this same code below as a lookup table and I know I need some randomness so it is not predictable.

For this example below, the scenario would be which down are we in (4th in this example), how many yards to go (2 yards), the offensive's team running attribute (choice = Bears), the defense run attribute (o_choice = Bengals) and the play called (playbook_choice = 1 which is QB Sneak). Any help would be much appreciated, I have been banging my head against on the wall on this. I have not incorporated the attributes ratings below into the code below because I am not sure how. The Bears would have offensive running and pass ratings, and defensive running and pass ratings (so 4 ratings in total), same goes for the Bengals.

    //test logic
if (playbook_choice == 1 && choice == 1 && o_choice == 2) { //if qb sneak is called by the user controlled bears vs the cpu bengals

int current_down_yards = 0,down = 4 ,yards = 2; // current down is 4th and 2  --- setting the down and distance
cout << "It is 4th down and 2 yards to go" << endl; // print it out to the user --- setting the down and distance

if (down == 2 || down == 3 || down == 4 && yards < 3) { //if its 2nd , 3rd of 4th down  and less than 3 yards to go
current_down_yards = rand() % 16; // give a rate of completion of randomness from 1-15 yards for a QB sneak --- need to take account for the strength
// of the defense's attribute rating and offense's running rating -- to include for a loss as well as a gain in yardage
cout << "The QB ran for " << current_down_yards << " " << "yards" << endl;
}
}

• I know nothing about the game (I'm guessing it is handegg?) Anyway, I would have a look at statemachines for your playbooks. See this link. This gives you a way to structure code without all the if statements. Also you can make functions generic by having a match object with a team[] array. The opposing team is always team[1-myteamID] (given teams are 0 or 1). This way you can design functions from one team's perspective. – Felsir Dec 10 '18 at 13:26