The game of nim.

My game of nim is creating an infinite loop of saying "the mode is set to dumb." and "It is your turn." I need help in changing these loops to make them repeat but, I wouldn't know how to do it without the do-while loop. I know the while(pilesize!=1); is the problem but, I don't know how to fix it.

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
109
110
111
112
113
114
115
116
117
  // new project 1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <ctime>
#include <string>
#include <iostream>
#include <random>
int smartcomputer(int);
int dumbcomputer(int, int);
int turn(int, int);
using namespace std;


int main()
{
	bool flag = true;
	int marbletake = 0;
	string dumborsmart;
	srand(time(0));
	int pilesize = rand() % (100 - 10) + 10;
	cout << "Hello, Welcome to the game of Nim. Two players alternatively take marbles from a pile." << endl;
	cout << "Each move a player must take at least one marble but at most half of the marbles." << endl;
	cout << "Enter dumb for dumb mode and smart for smart mode." << endl;
	getline(cin, dumborsmart);
	
	do {
		if (dumborsmart == "dumb") {
			cout << "The mode is set to dumb." << endl;//set to dumb
			bool turn = rand() % 2;
			if (turn = true) {
				cout << "It is your turn" << endl;
			}
			else {
				cout << "It is the bots turn" << endl;
			}
			if (turn = false) {      //not player's turn=false
				if (dumborsmart == "dumb") {
					dumbcomputer(marbletake, pilesize);
				}
				else {
					smartcomputer(pilesize);
				}
			}
		}
		else {
			turn(marbletake, pilesize);
		}
	} while (pilesize != 1);
	
	return 0;
}

int turn(int marbletake,int pilesize){
	cout << "It is your turn. Marbles remaining in pile: " << pilesize << endl;
	cout << "Enter a number of marbles to remove from the pile" << endl;
	cin >> marbletake;
	if (marbletake > 1 && marbletake < (pilesize / 2)) {
		pilesize = pilesize - marbletake;
		cout << "Number of marbles in the pile: " << pilesize << endl;
		if (pilesize = 1) {
			cout << "You win. The bot is forced to take the last marble." << endl;
			system("pause");
			return 0;
		}
	}
	else {
		cout << "Error, please remove a number of marbles greater than 0 or less than half the pile." << endl;
		cin >> marbletake;
		pilesize = pilesize - marbletake;
		cout << "Number of marbles in the pile: " << pilesize << endl;
		if (pilesize = 1) {
			cout << "You win. The bot is forced to take the last marble." << endl;
			system("pause");
			return 0;
		}
	}
}
int smartcomputer(int pilesize){
	cout << "The bot is removing marbles from the pile." << endl;
	if (pilesize > 63) {
		pilesize = 63;
	}
	else if (pilesize > 31 && pilesize < 63) {
		pilesize = 31;
	}
	else if (pilesize > 15 && pilesize < 31) {
		pilesize = 15;
	}
	else if (pilesize > 7 && pilesize < 15) {
		pilesize = 7;
	}
	else if (pilesize > 3 && pilesize < 7) {
		pilesize = 3;
	}
	else {
		pilesize = pilesize - rand() % (pilesize / 2) + 1;
	}
	cout << "Number of marbles in the pile: " << pilesize << endl;
	if (pilesize = 1) {
		cout << "You lose. You are forced to take the last marble." << endl;
		system("pause");
		return 0;
	}
}
int dumbcomputer(int marbletake, int pilesize){
	cout << "The bot is removing marbles from the pile." << endl;
	pilesize = (pilesize - rand() % (pilesize / 2) + 1); // bot takes marbles from pile(half pile size-1)
	cout << "Number of marbles in the pile: " << pilesize << endl;
	if (pilesize = 1) {
		cout << "You lose. You are forced to take the last marble." << endl;
		system("pause");
		return 0;
	}
}

Also with my if(pilesize=1){ "You lose") aren't working as intended. Please help.
Topic archived. No new replies allowed.