so i have a rock paper scissor shoe program that just guesses a random # between 1 and three and guesses randomly then compares it to what you r=used to see who won. obviously this is very simple, but i would like to add a new difficulty, where the program actually uses basic AI to "learn" how to play the game and predict what you will move. obviously i know nothing about AI and dont know how to begin(but i imagine it is extremely complex), but is there a way i can get some sort of open source code for this kind of project? it is for school, and i will give credit where it is due for the AI....
i was thinking that kind of program, except of course in the terminal, with no images... (i dont plan on doing the veteran version which uses other data from other players, just the novice version that learns from you...)
here is my current code jsut to get an idea of how i wrote it thus fare:
#include <iostream>//could have used switch statements but do they work with bool values?
usingnamespace std;
//which is more efficient. byref or byval?
int comp_wins = 0;//1. to count wins/losses ties
int user_wins = 0;//2.
int ties = 0;//3.
int val1;
string val2;// takes string value, used in method stringint() to convert to int for computer
void win_check(int a, int b){//a is user input b is computer generated. 1 rock 2 paper 3 scicors
if((a == b) ){//when i do "a == b" output goes crazy,
cout<<"its a tie please try again!"<<endl;
cout<<""<<endl;
ties++;
}
elseif((a == 1 && b == 2) || (a == 2 && b == 3) || (a ==3 && b ==1)){
cout<<"I win"<<endl;
cout <<""<<endl;
comp_wins++;
}
if((b == 1 && a == 2) || (b == 2 && a == 3) || (a == 1 && b ==3)){
cout<<"You Win!"<<endl;
cout<<""<<endl;
user_wins++;
}
}
void rand_func(int val1){//should i use byreference or byvalue?
int a;
a = rand() % 3;
a +=1;
if(a == 1) {
cout<<"i chose rock"<<endl;
cout<<""<<endl;
win_check(val1, a);
}
elseif(a == 2){
cout<<"i chose paper"<<endl;
cout<<""<<endl;
win_check(val1, a);
}
elseif(a == 3){
cout<<"i chose scissors"<<endl;
cout<<""<<endl;
win_check(val1, a);
}
}
void stringint(string val2){
if(val2 == "rock" || val2 =="Rock"){
val1 = 1;
}
if(val2 == "paper" || val2 =="Paper"){
val1 = 2;
}
if(val2 == "scissors" || val2 =="Scissors"){
val1 = 3;
}
}
int main() {
int byte_count[2];
for (int i = 0; i <= 4; i++){
cout<<""<<endl;
cout<<""<<endl;
cout <<"Rock Paper or Scissors?"<<endl;
cin >> val2;
stringint(val2);
if(val1 == 1){
cout<<"you chose rock"<<endl;
rand_func(val1);
}if(val1 == 2){
cout<<"you chose paper"<<endl;
rand_func(val1);
}if(val1 == 3){
cout<<"you chose scissors"<<endl;
rand_func(val1);
}
if(i == 4){
cout<<"I won "<<comp_wins<<"/5 times"<<endl;
cout<<"You won "<<user_wins<<"/5 times"<<endl;
cout<<"We tied "<<ties<<"/5 times"<<endl;
}
}
return 0;
}
p.s. i would like the random geussing to be beginner, and AI to be hard
Hmm... AI for rock, paper and scissor? I must admit that I've never heard of it. AI for chess, checkers or other games is one thing, but this is quite unheard of (for me i.e.). I guess I'll have to see how this thread develops!
What Pravesh Koirala said... There is no such thing as "RPS AI", because there is nothing to learn.
I imagine you want some sort of statistical learning AI that keeps track of what you do and then "anticipates" what you will pick the next round. ("50% of times player went with Rock -> increase chance to pick paper!") It's not a bad idea as a learning assignment, but it's utterly useless as an AI, because you're making it more predictable. Aside from that, RPS is supposed to be an random/"uncorrelated" game: the outcome of round T has no impact on the choices in round T+1. There is nothing to measure, count or calculate that will help you predict anything.
It's an odd thing, Artificial Intelligence. More often than not, making it smarter makes it easier to defeat, hence why people who can beat a game on Hardest often get smashed when they play against other people.