LOL Game

In this program you will teach the computer how to play the LOL game. Here is how the game works: There is a game board which consists of a row
of n squares, all of them initially empty. There are two players: Player 1 and Player 2. The players take turns selecting an empty square (player 1 goes first) and writing either an “L” or an “O” in it. The player who first succeeds in completing an “LOL” in consecutive squares wins the game. If the whole board gets filled up without an LOL appearing consecutively anywhere, the game is a draw. Here are several things your program must do:

a)Your program must give the human player the ability to choose whether to go
first (player 1) or go second (player 2).

b) Your program must use an “x” to mark an empty square. At any point in the
game, the program should display how the board looks using “x”s, “L”s, and “O”s.
After the players each have two turns, this is an example of what your program
could display on the screen: “xLLxxxOxxL”. After each move, human or computer,
the program should display the current gameboard to the screen.

c)Your program must allow the human player to choose n, the number of squares.

d)In the cases where the human player chooses n =3,4,or 5,the program must have an easy mode and a hard mode. In the easy mode, the computer makes its
decisions randomly. It chooses an empty square randomly, and then randomly
chooses whether or not to put an “L” or an “O” in it. In the hard mode, the computer must play optimally.This means that you must figure out exactly who wins the game and how for these cases. Don’t worry about figuring out exactly how to play the game for n=6 or higher, as this is a pretty difficult task.If you figure out to do higher n values and incorporate it into your program (if you can handle n=7, for example),you will receive extra credit.

e)The program should ensure that the players make decisions that make sense in the context of the game.For example, it only makes sense for n to be greater than 2,so if the user enters an n-value that is 2 or less then the program should prompt the human user to enter a different number. Also, the program should prevent the human or computer player from choosing a square with an “L” or and “O” already written in it. If the human player chooses such a square,the program should prompt them for another choice (and continue prompting until the player makes a choice that makes sense).

This is the code that I currently have

#include<iostream>
#include<cmath>
#include<string>
#include<ctime>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;
int main(){
int player;
int emptynumber;
char mode;
int check = 0;
int boardplace;
char answer;
cout << "You are about to play the LOL game. The goal is to spell LOL in the game board." << endl;
cout << "First player to do so wins the game. Human would you like to go first or second? (1= first & 2=second)" << endl;
cin >> player;

if (player == 1)
cout << "Human you have choosen to go first" << endl;
else if (player == 2)
cout << "Human you have choosen to go second" << endl;
else {
cout << "Your entry is not valid please try agian." << endl;
cin >> player;
}

cout << "What mode would you like to play? e=easy and h=hard" << endl;
cin >> mode;
if (mode == 'e')
cout << "Human you have choosen to play the easy mode." << endl;
else if (mode == 'h')
cout << "Human you have choosen to play the hard mode." << endl;
else{
cout << "Human the mode that you have entered is invalid please try again." << endl;
cin >> mode;
}

cout << "How many positions would you like to have in this game?" << endl;
cin >> emptynumber;
while (emptynumber < 2){
cout << "Human the number of spaces that you have entered is invalid. Please try and enter an acceptable number." << endl;
cin >> emptynumber;
}

vector <char>spaces(emptynumber);
for (int i = 0; i < emptynumber; i++){
spaces[i] = 0;
cout << setw(5) << "x";
}
cout << endl;
while (player == 1 && mode == 'e'){
cout << "where would you like to place your L or O in the game board. Remember that the beginning position is at point 0" << endl;
cin >> boardplace;
if (boardplace > emptynumber){
cout << "You have tried to pick a place outside of the peramiters. Please try again?";
cin >> boardplace;
}


cout << "What letter would you like to place in the position selected?" << endl;
cin >> answer;
if (answer == 'L'){
cout << "You have choosen to place an L at position" << " " << boardplace;
}
else if (answer == 'O'){
cout << "You have choosen to place an O at position" << " " << boardplace;
}
else{
cout << "The letter you have tried to select is invalid. Please try again" << endl;
cin >> answer;
}


cout << "The current game board looks like" << endl;

spaces[boardplace] = answer;
for (int i = 0; i < emptynumber; i++){
cout << spaces[i] << " ";
}

cout << endl;
cout << "it is now the computers turn to choose a space and a letter";


}




while (player == 2 && mode == 'e');
while (player == 1 && mode == 'h');
while (player == 2 && mode == 'h');








system("pause");
return 0;

}
Last edited on
It looks like you're new to the forum so let me help you out with some friendly suggestions.

First, whenever you post code, try to wrap it in the [ code ] [ /code ] elements (remove spaces), so that it's easily distinguishable from surrounding text and the indenting is kept. You can insert these elements easily by hitting the icon that looks like <> in your text editor. Second, if your question resembles the requirements of a homework assignment, most people are not going to answer - as they assume you're trying to have someone do your homework for you; even if that's not your intention. Last, try to keep your question succinct and clear - only including the code snippets most relevant to your isolated question. Questions that generally get the best responses are those that:

1) Quickly describe an isolated problem the poster is having.
2) Includes relevant code snippets from the problem.
3) Details attempted fixes or thought-processes involved.

This shows that you've clearly identified a problem, have an idea where the issue may lie and have done your due diligence in trying to fix it.

Best of luck!
Last edited on
I don't get it... Where's the question??? I'll tag your code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

#include<iostream>
#include<cmath>
#include<string>
#include<ctime>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;
int main(){
int player;
int emptynumber;
char mode;
int check = 0;
int boardplace;
char answer;
cout << "You are about to play the LOL game. The goal is to spell LOL in the game board." << endl;
cout << "First player to do so wins the game. Human would you like to go first or second? (1= first & 2=second)" << endl;
cin >> player;

if (player == 1)
cout << "Human you have choosen to go first" << endl;
else if (player == 2)
cout << "Human you have choosen to go second" << endl;
else {
cout << "Your entry is not valid please try agian." << endl;
cin >> player;
}

cout << "What mode would you like to play? e=easy and h=hard" << endl;
cin >> mode;
if (mode == 'e')
cout << "Human you have choosen to play the easy mode." << endl;
else if (mode == 'h')
cout << "Human you have choosen to play the hard mode." << endl;
else{
cout << "Human the mode that you have entered is invalid please try again." << endl;
cin >> mode;
}

cout << "How many positions would you like to have in this game?" << endl;
cin >> emptynumber;
while (emptynumber < 2){
cout << "Human the number of spaces that you have entered is invalid. Please try and enter an acceptable number." << endl;
cin >> emptynumber;
}

vector <char>spaces(emptynumber);
for (int i = 0; i < emptynumber; i++){
spaces[i] = 0;
cout << setw(5) << "x";
}
cout << endl;
while (player == 1 && mode == 'e'){
cout << "where would you like to place your L or O in the game board. Remember that the beginning position is at point 0" << endl;
cin >> boardplace;
if (boardplace > emptynumber){
cout << "You have tried to pick a place outside of the peramiters. Please try again?";
cin >> boardplace;
}


cout << "What letter would you like to place in the position selected?" << endl;
cin >> answer;
if (answer == 'L'){
cout << "You have choosen to place an L at position" << " " << boardplace;
}
else if (answer == 'O'){
cout << "You have choosen to place an O at position" << " " << boardplace;
}
else{
cout << "The letter you have tried to select is invalid. Please try again" << endl;
cin >> answer;
}


cout << "The current game board looks like" << endl;

spaces[boardplace] = answer;
for (int i = 0; i < emptynumber; i++){
cout << spaces[i] << " ";
}

cout << endl;
cout << "it is now the computers turn to choose a space and a letter";


}




while (player == 2 && mode == 'e');
while (player == 1 && mode == 'h');
while (player == 2 && mode == 'h');








system("pause");
return 0;

}


PS:When I read your title I thought you were recreating league of legends. that made me jump :D
Last edited on
Topic archived. No new replies allowed.