permenant headach

closed account (N8MNAqkS)
so here if something I am working on. its not done and im gonna estimate it will take me about a month to complete but its hexapon. google it.
let me know if there is any way I can simplify this.
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 include "pch.h"
#include <iostream>
#include <Windows.h>
#include "MatchBox.h"
#include <string>
#include <chrono>
#include <random>
using namespace std;

int main()
{
	GameLogic GameStart;
	GameStart.MatchStart();

	return 0;
}

void GameLogic::MatchStart()
{
	//board//
	cout << "\n************************************************************";
	cout << "\n*       ROOK1     *        KING1           *     ROOK1     *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n************************************************************";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n************************************************************";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*       ROOK2     *        KING2           *     ROOK2     *";
	cout << "\n************************************************************";

bool Left = true, Right = true, Middle = true;
	int i = 0;

	cout << "\nChoose your move\n\n(1)'left'\n\n(2)'middle'\n\n(3)'right'\n\n";
	cin >> i;

	if (i == 1)
	{
     Left = false;
	}
	else 
	{}
	if (i == 2)
	{
      Middle = false;
	}
	else 
	{}
	if (i == 3)
	{
     Right = false;
	}
	else 
	{}
		   //Scenario where player moves left//
		   if (Left)
		   {}
		   else 
		   {
			   GameLogic MoveLeft;
			   MoveLeft.PlayerMoveLeft();
		   }
		   //Scenario where player moves middle//
		   if (Middle)
		   {}
		   else 
		   {
			   GameLogic MoveMiddle;
			   MoveMiddle.PlayerMoveMiddle();
		   }
		   //Scenario where player moves right//
		   if (Right)
		   {}
		   else 
		   {
			   GameLogic MoveRight;
			   MoveRight.PlayerMoveRight();
		   }
}

void GameLogic::PlayerMoveLeft()
{
	//board//
	cout << "\n************************************************************";
	cout << "\n*       ROOK1     *         KING1          *       ROOK1   *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n************************************************************";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*        ROOK2    *                        *               *";
	cout << "\n************************************************************";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *                        *               *";
	cout << "\n*                 *        KING2           *       ROOK2   *";
	cout << "\n************************************************************";

	bool kill1 = true, Right1 = true, Middle1 = true;
	int i = 0;

	cout << "\n\nChoose your move\n\n(1)Computers Turn\n\n";
	cin >> i;

	
	unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
	std::mt19937 generator(seed);
	std::uniform_int_distribution<int> distribution(1, 3);

	int PRN;
	PRN = distribution(generator);

	if (PRN == 1)
	{
		kill1 = false;
	}
	else
	{
	}
	if (PRN == 2)
	{
		Middle1 = false;
	}
	else
	{
	}
	if (PRN == 3)
	{
		Right1 = false;
	}
	else
	{
	}

	//Scenario where Computer moves left//
	if (kill1)
	{
	}
	else
	{
		cout << "to be continued1";
	}
	//Scenario where Computer moves middle//
	if (Middle1)
	{
	}
	else
	{
		cout << "to be continued2";
	}
	//Scenario where Computer moves right//
	if (Right1)
	{
	}
	else
	{
		cout << "to be continued3";
	}
}

void GameLogic::PlayerMoveMiddle()
{
	
}
void GameLogic::PlayerMoveRight()
{
	
}


HEADER FILE

#pragma once
class GameLogic
{
public:

void MatchStart();

void PlayerMoveLeft();

void PlayerMoveMiddle();

void PlayerMoveRight();


int i = 0;
};
Last edited on
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
	if (i == 1)
	{
     Left = false;
	}
	else 
	{}
	if (i == 2)
	{
      Middle = false;
	}
	else 
	{}
	if (i == 3)
	{
     Right = false;
	}
	else 
	{}
		   //Scenario where player moves left//
		   if (Left)
		   {}
		   else 
		   {
			   GameLogic MoveLeft;
			   MoveLeft.PlayerMoveLeft();
		   }
		   //Scenario where player moves middle//
		   if (Middle)
		   {}
		   else 
		   {
			   GameLogic MoveMiddle;
			   MoveMiddle.PlayerMoveMiddle();
		   }
		   //Scenario where player moves right//
		   if (Right)
		   {}
		   else 
		   {
			   GameLogic MoveRight;
			   MoveRight.PlayerMoveRight();
		   }

This is bizarrely formatted. Is that intentional?

Your logic, formatted, looks like this:
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
	if (i == 1)
	{
		Left = false;
	}
	else 
	{
		// Nothing
	}
	if (i == 2)
	{
		Middle = false;
	}
	else 
	{
		// Nothing
	}
	if (i == 3)
	{
		Right = false;
	}
	else 
	{
	
	}
	
	//Scenario where player moves left//
	if (Left)
	{
		// Nothing
	}
	else 
	{
	   GameLogic MoveLeft;
	   MoveLeft.PlayerMoveLeft();
	}
	
	//Scenario where player moves middle//
	if (Middle)
	{
		// Nothing
	}
	else 
	{
	   GameLogic MoveMiddle;
	   MoveMiddle.PlayerMoveMiddle();
	}
	
	//Scenario where player moves right//
	if (Right)
	{
		// Nothing
	}
	else 
	{
	   GameLogic MoveRight;
	   MoveRight.PlayerMoveRight();
	}

Are all of those blank if bodies intentional?

Some tips in no particular order:
- Don't just draw a hard-coded board. Separate your logic to draw the board, and plug in what is in each position, perhaps based on something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
enum class Piece {
	Empty,
	Rook1,
	King1,
	Rook2,
	King2
};
// ...
	Piece board[3][3] = {
		{ Rook1, King1, Rook1 },
		{ Rook2, Empty, Empty },
		{ Empty, King2, Rook2 }
	};

- Don't seed your RNG more than once, you'll just get the same numbers if the logic loops more than once a second.
- You define a class-scope variable called "i", which is a bad name to begin with, but then also make local i variables in your functions. Avoid using "i" as a variable except as simple for-loop counters.
- You never use any functionality from <Windows.h>, so don't include it. Doing so limits the ability of your code to compile on other platforms.
Last edited on
closed account (N8MNAqkS)
thx for the idea for the board.

and yes those blank if bodies are intentional. in certain situations I dont want then to do anything, so by saying

if(blah)
{
//do nothing
}
else
{
do something
}

its just how I do it. we all code differently ;)

as for the windows.h I just plug in as many libraries as I can remember cuz some code I use requires them and I cant be bothered to remember which libraries the code comes from.
The empty elses and all are visual clutter. They don't hurt but its an eyesore IMHO.

left/middle/right may be redundant. It looks to me like left/middle/right can just be removed and use 'i' in the logic tests directly.
But its not done, maybe you need the variables for other stuff later?

to draw the generic board and pieces, something like...
string words[max_enum];

1
2
3
4
5
words[nothing] = "     ";
words[rook1] = "rook1"
… etc..
then cout << "\n*        "<< words[some_index] <<  "  
etc... see? 


the key here vs the above is to have the list of strings -- tied by index to the enum -- that makes it easy to print the board like you need it.
Last edited on
closed account (N8MNAqkS)
I am not totally sure how to use enum yet, but i will look into it. And the left middle right stuff is mostly for me. As it would be hard to read if every bool or int was just i.
Topic archived. No new replies allowed.