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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
[code]
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
//functions
void pepegaquarters(std::string position[][99] ,int x , int y , std::string choice);
void infintyikea(int x , int y , std::string position[][99]);
bool checkposition(int x , int y, std::string position[][99], int truex , int truey);
void pepegaassign(int truex, int truey , std::string position[][99] , std::string choice , int i) ;
bool wincon(std::string position[][99] , int x ,int y ,int stepx , int stepy);
int main()
{
int realx,realy,boardcounter,truex,truey,pepegainput = 1;
std::string position[99][99] , choice;
std::cout << " WELCOME TO 4- CONNECT \n _______________________________\n";
boardcounter = 1;
std::cout << "can u tell us about the rows of the board : ";
std::cin >> realx;
std::cout << "and the coloumns pls: ";
std::cin >> realy;
std::cout << "\n";
for(int i = 0; i < realx ; i++ ){
for(int j = 0 ; j < realy ; j++){
position[i][j] = std::to_string(boardcounter);
boardcounter++;
}
}
infintyikea(realx , realy , position);
std::cout << "\ncan u pls input the color :";
std::cin >> choice;
std::cout << "\n";
pepegaquarters(position , realx , realy , choice);
std::cin.ignore();
std::cin.get();
}
void pepegaquarters(std::string position[][99], int x , int y , std::string choice)
{
if(choice != "red" && choice != "blue")
std::cout << "\nERROR";
else {
int truex , truey , pepegainput;
int i = 0;
for( ; ;){
system("CLS");
//ask the user
if(i == 0)
std::cout << "1st player pls input (number in the board) ";
else if (!(i % 2 == 0)){
std::cout << "2ed player pls input ";
}
else if (i % 2 == 0){
std::cout <<"1st player pls input ";
}
std::cout << "\n\n";
infintyikea(x , y ,position);
std::cout << "\n:";
std::cin >> pepegainput;
//big brain equations
truex = ((pepegainput + (x+1)) / x) - 1;
truey = (pepegainput % y) - 1;
if(pepegainput % y == 0){
truey = (pepegainput -1)%y;}
if(checkposition(x , y ,position , truex , truey) == true){
pepegaassign(truex , truey , position , choice , i);
}
else if (checkposition(x , y ,position , truex , truey) != true){
std::cout << "\n EROOR";
}
if(wincon(position , x , y , 0 , 1) || wincon(position , x , y , 1 , 0) || wincon(position , x , y , 1 , 1) || wincon(position , x , y , 1 , -1) == true ){
std::cout << "\n";
if(i % 2 == 0)
std::cout <<"congrats first player won !!!";
else if(!(i% 2 == 0)) {
std::cout << "congrats 2ed player won !!!";}
break;
}
i++;
}
}
}
void infintyikea(int x , int y , std::string position[][99])
{
for(int i = 0 ; i < x ; i++){
for( int j = 0 ; j < y ; j++){
std::cout << position[i][j];
// weird useless sht
std::stringstream geek(position[i][j]);
int z = 0;
geek >> z;
if(position[i][j] == "r"||position[i][j] == "b" && i*z > 9){
std::cout << " | ";
}
else if(z > 99 ){
std::cout << "| ";
}
else if(z > 9){
std::cout << " | ";
}
else{
std::cout << " | ";}
}
std::cout << "\n";
}
}
bool checkposition(int x , int y , std::string position[][99], int truex , int truey)
{
int trueboard;
trueboard = truex * truey;
if(truex > x || truey > y )
return false;
else if(position[truex][truey] == "R" || position[truex][truey] == "B")
return false;
else
return true;
}
void pepegaassign(int truex , int truey , std::string position[][99] , std::string choice , int i)
{
if(choice == "red"){
if(i % 2 == 0)
position[truex][truey] = "r";
else if (!(i % 2 == 0))
position[truex][truey] = "b";
}
if(choice =="blue"){
if(i % 2 == 0)
position[truex][truey] = "b";
else if (!(i % 2 == 0))
position[truex][truey] = "r";
}
}
bool wincon(std::string position[][99] ,int x ,int y ,int stepx ,int stepy)
{
for(int i = 0 ;i < x ; i++ ){
for(int j = 0 ; j < y ; j++){
std::string startvalue = position[i][j];
for (int b = 1; b < 4 ; ++b){
if( position[i+ b*stepx][j+ b*stepy] != startvalue){
return false;
}
}
return true;
}
}
}
|