I'm trying to implement a simple version of Wari logical board game. My implementation supposes to allow two humans to play the game. I have created array of 12 elements, each element represent the square. Every square has a number of stones. My problem is that I don’t know how to manipulate, get access, and change the "square", "numStones" variables.
The program is so far:

// Wari 

#include <iostream>
#include <stdio.h>       
#include <stdlib.h>
#include <math.h>

using namespace std;

int i;
int m = 0;
bool exitGame = false;
int numStones = 4;

int score1 = 0;
int score2 = 0;
const int arraySize =12;


char side1[] = {'f','e','d','c','b','a'};
char side2[] = {'A','B','C','D','E','F'};
int board[12];


void printSide1(char side1[6])
{
    for ( int n = 0; n < 6 ; n++)
    {
        cout <<" " << side1[n] <<" ";
    }
    cout<<endl;
}

void printSide2(char side2[6])
{
    for ( int m = 0; m < 6 ; m++)
    {
        cout <<" " << side2[m] <<" ";
    }
    cout<<endl;
}

bool emptySquare(){
    if(square == 0) return true;
    return false;}


void printBoard(int board[12] )          
{ 

    for (int i=0; i<13; i++)
    {

        if(i==6) cout << endl;

        else    cout << " " << numStones << " ";

    }
    cout<< endl;
}




void Update(int board[], int square, int numStones)
{   
    //content
}


void gameDisplay()
{

    printSide1(side1);
    printBoard(board);
    Update( board, square, numStones);
    printSide2(side2);
}

bool illegalMove1()
{
    bool legal = (square >= 0 && square <= 5);
    return !legal;
}

bool illegalMove2()
{
    bool legal = (square >= 6 && square <= 11);
    return !legal;
}

void Move_Player1()
{
    do 
    {
        cout << "Player1, please make your move: f, e, d, c, b , a..." <<endl;
        cin >> square;

        switch(square)
        {
        case 'f':
            square = 0;
            break;
        case 'e':
            square = 1;
            break;
        case 'd':
            square = 2;
            break;
        case 'c':
            square = 2;
            break;
        case 'b':
            square = 3;
            break;
        case 'a':
            square = 4;
            break;
        }
        cout << "square index:" << (int)square << endl;


    }while ( illegalMove1() );
}


void Move_Player2()
{
    do
    {
        cout << "Player2, please make your move: A, B, C, D, E, F..." <<endl;
        cin >> square;

        switch(square)
        {
        case 'A':
            square = 6;
            break;
        case 'B':
            square = 7;
            break;
        case 'C':
            square = 8;
            break;
        case 'D':
            square = 9;
            break;
        case 'E':
            square = 10;
            break;
        case 'F':
            square = 11;
            break;
        }

        cout << "square index:" << (int)square << endl;


    }
    while (illegalMove2());
}


int main()
{    

    int score1 = 0;
    int score2 = 0;

    cout<< endl;
    cout<<" WELCOME TO THE GAME OF WARI" <<endl;
    cout<< endl;



    cout<<"Player1 score: "<< score1 <<endl;
    cout<<"Player2 score: "<< score2 <<endl;

    cout << endl;


    while( !exitGame)
    {

        if (m % 2 == 0)
        {
            Move_Player1();
        }
        else
        {
            Move_Player2();
        }
        m++;

        gameDisplay();

        if( score1 == 25 || score2 == 25)
        {
            exitGame = true;
        }

        if(exitGame == true)
        {
            cout << "Winner is :" <<endl;
        }
    }
}

Thank you.
Below you can see the actual output after compiling the code.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Attachments console.jpg 62.57 KB

It's a slash in (/code), not a backslash. But A for effort. :D
And you can supply the language as well, (code=cpp)

Your code looks okay, but it looks a lot like C: it's not using OOP. Which would be a nice approach for a board game.

My output looks a bit different too:

||=== TMP, Debug ===|
main.cpp||In function `bool emptySquare()':|
main.cpp|40|error: `square' was not declared in this scope|
main.cpp|40|warning: unused variable 'square'|
main.cpp||In function `void gameDisplay()':|
main.cpp|69|error: `square' was not declared in this scope|
main.cpp|69|warning: unused variable 'square'|
main.cpp||In function `bool illegalMove1()':|
main.cpp|74|error: `square' was not declared in this scope|
main.cpp||In function `bool illegalMove2()':|
main.cpp|79|error: `square' was not declared in this scope|
main.cpp||In function `void Move_Player1()':|
main.cpp|86|error: `square' was not declared in this scope|
main.cpp||In function `void Move_Player2()':|
main.cpp|118|error: `square' was not declared in this scope|
||=== Build finished: 6 errors, 2 warnings ===|

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Clockowl :)
Thank you. You are right. I have missed the "square" declaration at the beginning.

char square = 'z';

Now it compiles without any errors and warnings with MVS 2008 as C++ project.

OOP aproach:
board.h:

#ifndef BOARD_H
#define BOARD_H

class Board
{
public:
	Board();
	~Board(){}

};
#endif

board.cpp:

#include "board.h"
Board::Board()
{

}

game.h:

#ifndef GAME_H
#define GAME_H
class Game
{
public:
	Game();
	~Game(){}
    int Update;
	int Move;
	int GetScore();
	int DisplayScore();

	int SetScore1(int score1);
	int SetScore2(int score2);
    
	int m_score1;
	int m_score2;
};
#endif

game.cpp:

#include "game.h"

Game::Game()
{

}

int Game::Update()
{

}
int Game::Move()
{

}
int Game::SetScore1(int score1)
{

}
int Game::SetScore1(int score2)
{

}
int Game::DisplayScore()
{
	std::cout<<"Player1 score: "<<score1<<"Player2 score: "<<score2<<endl;
}

square.h:

#ifndef SQUARE_H
#define SQUARE_H

class Square
{
public:
	Square();
	~Square(){}
void SetValues();

int m_array[12];

};
#endif

square.cpp:

#include "square.h"
Square::Square()
{

}
int Square::SetValues(int m_array[])
{

}

stone.h:

#ifndef STONE_H
#define STONE_H

class Stone
{
public:
	Stone();
	~Stone(){}
int SetValues();

};
#endif

stone.cpp:

#include "stone.h"
Stone::Stone()
{

}

main.cpp:

#include "GAME.h"
#include "BOARD.h"
#include "SQUARE.h"
#include "STONE.h"

#include <iostream>
using namespace std;

int main()
{

board b;
b.SetValues();
b.DisplayScore();

return 0;
}

It is just one of those moments then I'm a bit lost how to get functionality from the code.

Decide the interactions. What controls the stones? How will they control the stones? Do more objects need to know the stones' places? All that stuff. Maybe read some tutorials on OOP, they can get you going. :)

This article has been dead for over six months. Start a new discussion instead.