I am having some problems with a program that I have due soon....I could use some serious help. I am going to post the requirements in this post, if you can help please let me know!

Recommended Answers

All 11 Replies

What steps have you taken in starting to solve the problem? Have you decided on how you will represent the board? Are you going to use classes? These are the things you need to think about and start sketching out on paper even before you begin. Write as much of the code as you can, and post back with specific issues.

So far I have the board set up, its in an array. The areas that will remain blank I have issued to be null,. And the other spots have been assigned fox,sheep, or the numbers. The issues I'm having are coming up with functions to print the board out and to have a human played be active with the "computer."

I have gotten a little further in the project since I last posted, I have the fox on a board that is able to move around now. I am now having issues getting the sheep added into the mix and getting the board in the shape that I need it. I am going to post my code and if anyone has any suggestions please let me know! Thank you!

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

#include "sheep.h"
#include "fox.h"

using namespace std;

char gameBoard[8][8];


void init_gameBoard()
{
    gameBoard[7][0] = '7';
    gameBoard[7][1] = ' ';
    gameBoard[7][2] = ' ';
    gameBoard[7][3] = 'f';
    gameBoard[7][4] = '.';
    gameBoard[7][5] = 'f';
    gameBoard[7][6] = ' ';
    gameBoard[7][7] = ' ';

    gameBoard[6][0] = '6';
    gameBoard[6][1] = ' ';
    gameBoard[6][2] = ' ';
    gameBoard[6][3] = '.';
    gameBoard[6][4] = '.';
    gameBoard[6][5] = '.';
    gameBoard[6][6] = ' ';
    gameBoard[6][7] = ' ';

    gameBoard[5][0] = '5';
    gameBoard[5][1] = '.';
    gameBoard[5][2] = '.';
    gameBoard[5][3] = '.';
    gameBoard[5][4] = '.';
    gameBoard[5][5] = '.';
    gameBoard[5][6] = '.';
    gameBoard[5][7] = '.';

    gameBoard[4][0] = '4';
    gameBoard[4][1] = 's';
    gameBoard[4][2] = 's';
    gameBoard[4][3] = 's';
    gameBoard[4][4] = 's';
    gameBoard[4][5] = 's';
    gameBoard[4][6] = 's';
    gameBoard[4][7] = 's';

    gameBoard[3][0] = '3';
    gameBoard[3][1] = 's';
    gameBoard[3][2] = 's';
    gameBoard[3][3] = 's';
    gameBoard[3][4] = 's';
    gameBoard[3][5] = 's';
    gameBoard[3][6] = 's';
    gameBoard[3][7] = 's';

    gameBoard[2][0] = '2';
    gameBoard[2][1] = ' ';
    gameBoard[2][2] = ' ';
    gameBoard[2][3] = 's';
    gameBoard[2][4] = 's';
    gameBoard[2][5] = 's';
    gameBoard[2][6] = ' ';
    gameBoard[2][7] = ' ';

    gameBoard[1][0] = '1';
    gameBoard[1][1] = ' ';
    gameBoard[1][2] = ' ';
    gameBoard[1][3] = 's';
    gameBoard[1][4] = 's';
    gameBoard[1][5] = 's';
    gameBoard[1][6] = ' ';
    gameBoard[1][7] = ' ';

    gameBoard[0][0] = ' ';
    gameBoard[0][1] = 'a';
    gameBoard[0][2] = 'b';
    gameBoard[0][3] = 'c';
    gameBoard[0][4] = 'd';
    gameBoard[0][5] = 'e';
    gameBoard[0][6] = 'f';
    gameBoard[0][7] = 'g';
}

void print_gameBoard()
{
    gameBoard[7][0] = '7';
    gameBoard[7][1] = ' ';
    gameBoard[7][2] = ' ';
    gameBoard[7][3] = 'f';
    gameBoard[7][4] = '.';
    gameBoard[7][5] = 'f';
    gameBoard[7][6] = ' ';
    gameBoard[7][7] = ' ';

    gameBoard[6][0] = '6';
    gameBoard[6][1] = ' ';
    gameBoard[6][2] = ' ';
    gameBoard[6][3] = '.';
    gameBoard[6][4] = '.';
    gameBoard[6][5] = '.';
    gameBoard[6][6] = ' ';
    gameBoard[6][7] = ' ';

    gameBoard[5][0] = '5';
    gameBoard[5][1] = '.';
    gameBoard[5][2] = '.';
    gameBoard[5][3] = '.';
    gameBoard[5][4] = '.';
    gameBoard[5][5] = '.';
    gameBoard[5][6] = '.';
    gameBoard[5][7] = '.';

    gameBoard[4][0] = '4';
    gameBoard[4][1] = 's';
    gameBoard[4][2] = 's';
    gameBoard[4][3] = 's';
    gameBoard[4][4] = 's';
    gameBoard[4][5] = 's';
    gameBoard[4][6] = 's';
    gameBoard[4][7] = 's';

    gameBoard[3][0] = '3';
    gameBoard[3][1] = 's';
    gameBoard[3][2] = 's';
    gameBoard[3][3] = 's';
    gameBoard[3][4] = 's';
    gameBoard[3][5] = 's';
    gameBoard[3][6] = 's';
    gameBoard[3][7] = 's';

    gameBoard[2][0] = '2';
    gameBoard[2][1] = ' ';
    gameBoard[2][2] = ' ';
    gameBoard[2][3] = 's';
    gameBoard[2][4] = 's';
    gameBoard[2][5] = 's';
    gameBoard[2][6] = ' ';
    gameBoard[2][7] = ' ';

    gameBoard[1][0] = '1';
    gameBoard[1][1] = ' ';
    gameBoard[1][2] = ' ';
    gameBoard[1][3] = 's';
    gameBoard[1][4] = 's';
    gameBoard[1][5] = 's';
    gameBoard[1][6] = ' ';
    gameBoard[1][7] = ' ';

    gameBoard[0][0] = ' ';
    gameBoard[0][1] = 'a';
    gameBoard[0][2] = 'b';
    gameBoard[0][3] = 'c';
    gameBoard[0][4] = 'd';
    gameBoard[0][5] = 'e';
    gameBoard[0][6] = 'f';
    gameBoard[0][7] = 'g';


}




int main()
{
        // Fox 0 Old Location and New Location Variables

        int Fox0FirstX;
        int Fox0FirstY;
        int Fox0NewX;
        int Fox0NewY;

        // Fox 1 Old Lcation and New Locatino Variables

        int Fox1FirstX;
        int Fox1FirstY;
        int Fox1NewX;
        int Fox1NewY;

        int Sheep1;
        int Sheep2;

        sheep Flock[20]; // Array of Sheep
        fox Duo[2]; // Array of Foxes






            cout <<"Move Fox0 to?"<<endl;  // Pick Fox0 on the board, and move it to this location
            cin >> Fox0FirstX >> Fox0FirstY >> Fox0NewX >> Fox0NewY;
            Duo[0].move(Fox0FirstX,Fox0FirstY, Fox0NewX,Fox0NewY); // move Fox0


            cout <<"Move Fox1 to?"<<endl; // Pick Fox1 on the board, and move it to this location
            cin >> Fox1FirstX >> Fox1FirstY >> Fox1NewX >> Fox1NewY;
            Duo[1].move(Fox1FirstX,Fox1FirstY, Fox1NewX,Fox1NewY); // move Fox0



                for (int i = 0; i<8; i++)   // I and J print the 8 Rows and 8 Columns
                 {
                     for (int j =8; j>0; j--)
                     {

                        gameBoard[i][j] = '*';  // By default prints '*'
                        gameBoard[Fox0NewX][Fox0NewY] = 'F'; // Prints 'F' where Fox0 is located.
                        gameBoard[Fox1NewX][Fox1NewY] = 'F';// Prints F where Fox1 is located.

                        gameBoard[Fox0FirstX][Fox0FirstY] = '*'; // Prints 'F' where Fox0 is located.
                        gameBoard[Fox1FirstX][Fox1FirstY] = '*';// Prints F where Fox1 is located.
                        cout <<gameBoard[i][j]; // Prints New GameBoard

                     }




                     cout << endl;
                 }






       }


        //init_gameBoard();
        //print_gameBoard();

fox.h:

#ifndef FOX_H_INCLUDED
#define FOX_H_INCLUDED


class fox
{
    public:

    fox() {id = 0; xLoc = 0; yLoc = 0;}
    fox(int I, int X, int Y) { id = I; xLoc = X; yLoc = Y;}
    void move(int CurrentX, int currentY, int FinalX, int FinalY);

    int GetID(){return id;}
    int GetxLoc() { return xLoc;}
    int GetyLoc() {return yLoc;}

    void SetID(int I) {id = I;}
    void SetxLoc(int X) {xLoc = X;}
    void SetyLoc(int Y) {yLoc = Y;}

    private:

    int id;
    int xLoc;
    int yLoc;
};



 void fox::move(int CurrentX, int CurrentY, int FinalX, int FinalY)
{
SetxLoc(CurrentX);
SetyLoc(CurrentY);
}

sheep.h:

#ifndef SHEEP_H_INCLUDED
#define SHEEP_H_INCLUDED

class sheep
{
    public:

    sheep() {id = 0; xLoc = 0; yLoc = 0;}
    sheep(int I, int X, int Y) { id = I; xLoc = X; yLoc = Y;}
    void move(int CurrentX, int currentY, int FinalX, int FinalY);

    int GetID(){return id;}
    int GetxLoc() { return xLoc;}
    int GetyLoc() {return yLoc;}

    void SetID(int I) {id = I;}
    void SetxLoc(int X) {xLoc = X;}
    void SetyLoc(int Y) {yLoc = Y;}

    private:

    int id;
    int xLoc;
    int yLoc;
}; //sssotg

#endif // SHEEP_H_INCLUDED


void sheep::move (int currentX, int currentY, int FinalX, int FinalY)
{
SetxLoc(FinalX);
SetyLoc(FinalY);
}

The game board is the tricky part because it's not square. It's probably most convenient to make it a square and then do bounds checking to make sure the move you are going to make is still on the board. You should probably do this in the move function with a series of if statements. You can also adjust your board within the move function.

Your displayboard function doesn't make much sense. Just output it using a loop like you were trying to do in the main function. Adjust the bounds on your for loops to print out only the valid portions.

Keep going with it, and test it incrementally to make sure all of the parts are working before moving on.

So I worked on this today and this is what I have so far:
I have the foxes and the sheep on the board but the foxes are only able to move. The row column format is in (x1,y1) and (x2,y2). Meaning that when you are prompted to move the first fox you will choose a starting point and the ending point on where you want it to be. You will then be prompted for the second fox and the same will be asked of you. I used an array to print out the board and made a simple square board; once this was done I just adjusted the boundaries to shape the board. The board will terminate after the loop is done which will be printed twice. I used classes to create my foxes and my sheep with a set of functions. The foxes move based off a move function. To get the foxes in the starting positions that they need to be, set your foxes to move and end up at (7,3) and (7,5). Meaning for instance when you are prompted enter for example 7 7 7 3 and 7 7 7 5 to get them where they need to be.

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

#include "sheep.h"
#include "fox.h"

using namespace std;

char gameBoard[8][8];


void Blank_gameBoard()
{
    gameBoard[7][0] = '7';
    gameBoard[7][1] = ' ';
    gameBoard[7][2] = ' ';
    gameBoard[7][3] = '.';
    gameBoard[7][4] = '.';
    gameBoard[7][5] = '.';
    gameBoard[7][6] = ' ';
    gameBoard[7][7] = ' ';

    gameBoard[6][0] = '6';
    gameBoard[6][1] = ' ';
    gameBoard[6][2] = ' ';
    gameBoard[6][3] = '.';
    gameBoard[6][4] = '.';
    gameBoard[6][5] = '.';
    gameBoard[6][6] = ' ';
    gameBoard[6][7] = ' ';

    gameBoard[5][0] = '5';
    gameBoard[5][1] = '.';
    gameBoard[5][2] = '.';
    gameBoard[5][3] = '.';
    gameBoard[5][4] = '.';
    gameBoard[5][5] = '.';
    gameBoard[5][6] = '.';
    gameBoard[5][7] = '.';

    gameBoard[4][0] = '4';
    gameBoard[4][1] = '.';
    gameBoard[4][2] = '.';
    gameBoard[4][3] = '.';
    gameBoard[4][4] = '.';
    gameBoard[4][5] = '.';
    gameBoard[4][6] = '.';
    gameBoard[4][7] = '.';

    gameBoard[3][0] = '3';
    gameBoard[3][1] = '.';
    gameBoard[3][2] = '.';
    gameBoard[3][3] = '.';
    gameBoard[3][4] = '.';
    gameBoard[3][5] = '.';
    gameBoard[3][6] = '.';
    gameBoard[3][7] = '.';

    gameBoard[2][0] = '2';
    gameBoard[2][1] = ' ';
    gameBoard[2][2] = ' ';
    gameBoard[2][3] = '.';
    gameBoard[2][4] = '.';
    gameBoard[2][5] = '.';
    gameBoard[2][6] = ' ';
    gameBoard[2][7] = ' ';

    gameBoard[1][0] = '1';
    gameBoard[1][1] = ' ';
    gameBoard[1][2] = ' ';
    gameBoard[1][3] = '.';
    gameBoard[1][4] = '.';
    gameBoard[1][5] = '.';
    gameBoard[1][6] = ' ';
    gameBoard[1][7] = ' ';

    gameBoard[0][0] = ' ';
    gameBoard[0][1] = 'a';
    gameBoard[0][2] = 'b';
    gameBoard[0][3] = 'c';
    gameBoard[0][4] = 'd';
    gameBoard[0][5] = 'e';
    gameBoard[0][6] = 'f';
    gameBoard[0][7] = 'g';

    for (int i = 7; i>=0; i--)
     {
        for (int j =0; j<=7; j++)
        {
            cout << gameBoard[i][j];
        }
        cout << endl;
     }
}



int main()
{
        // Fox 0 Old Location and New Location Variables

        int Fox0FirstX =-1;
        int Fox0FirstY=-1;
        int Fox0NewX =-1;
        int Fox0NewY =-1;

        // Fox 1 Old Lcation and New Locatino Variables

        int Fox1FirstX =-1;
        int Fox1FirstY =-1;
        int Fox1NewX =-1;
        int Fox1NewY= -1;


        sheep Flock[20]; // Array of Sheep
        fox Duo[2]; // Array of Foxes

        int Sheep0_Ox;
        int Sheep0_Oy;
        int Sheep0_Nx;
        int Sheep0_Ny;


// ----------------------------------------------------------------------------- Default Board

// ----------------------------------------------------------------------------- Board

    gameBoard[7][0] = '7';
    gameBoard[7][1] = ' ';
    gameBoard[7][2] = ' ';
    gameBoard[7][3] = '.';
    gameBoard[7][4] = '.';
    gameBoard[7][5] = '.';
    gameBoard[7][6] = ' ';
    gameBoard[7][7] = ' ';

    gameBoard[6][0] = '6';
    gameBoard[6][1] = ' ';
    gameBoard[6][2] = ' ';
    gameBoard[6][3] = '.';
    gameBoard[6][4] = '.';
    gameBoard[6][5] = '.';
    gameBoard[6][6] = ' ';
    gameBoard[6][7] = ' ';

    gameBoard[5][0] = '5';
    gameBoard[5][1] = '.';
    gameBoard[5][2] = '.';
    gameBoard[5][3] = '.';
    gameBoard[5][4] = '.';
    gameBoard[5][5] = '.';
    gameBoard[5][6] = '.';
    gameBoard[5][7] = '.';

    gameBoard[4][0] = '4';
    gameBoard[4][1] = 'S';
    gameBoard[4][2] = 'S';
    gameBoard[4][3] = 'S';
    gameBoard[4][4] = 'S';
    gameBoard[4][5] = 'S';
    gameBoard[4][6] = 'S';
    gameBoard[4][7] = 'S';

    gameBoard[3][0] = '3';
    gameBoard[3][1] = 'S';
    gameBoard[3][2] = 'S';
    gameBoard[3][3] = 'S';
    gameBoard[3][4] = 'S';
    gameBoard[3][5] = 'S';
    gameBoard[3][6] = 'S';
    gameBoard[3][7] = 'S';

    gameBoard[2][0] = '2';
    gameBoard[2][1] = ' ';
    gameBoard[2][2] = ' ';
    gameBoard[2][3] = 'S';
    gameBoard[2][4] = 'S';
    gameBoard[2][5] = 'S';
    gameBoard[2][6] = ' ';
    gameBoard[2][7] = ' ';

    gameBoard[1][0] = '1';
    gameBoard[1][1] = ' ';
    gameBoard[1][2] = ' ';
    gameBoard[1][3] = 'S';
    gameBoard[1][4] = 'S';
    gameBoard[1][5] = 'S';
    gameBoard[1][6] = ' ';
    gameBoard[1][7] = ' ';

    gameBoard[0][0] = ' ';
    gameBoard[0][1] = 'a';
    gameBoard[0][2] = 'b';
    gameBoard[0][3] = 'c';
    gameBoard[0][4] = 'd';
    gameBoard[0][5] = 'e';
    gameBoard[0][6] = 'f';
    gameBoard[0][7] = 'g';




//------------------------------------------------------------------------------ Input Fox Locations

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

            cout <<"Your Move? Please Move Fox0 to in (x1,y1) to (x2, y2)?"<<endl;  // Pick Fox0 on the board, and move it to this location
            cin >> Fox0FirstX >> Fox0FirstY >> Fox0NewX >> Fox0NewY;
            Duo[0].move(Fox0FirstX,Fox0FirstY, Fox0NewX,Fox0NewY); // move Fox0
            gameBoard[Fox0FirstX][Fox0FirstY] = '.';
            gameBoard[Fox0NewX][Fox0NewY] = 'F';


            cout <<"Now Move Fox1 to in (x1,y1) to (x2, y2)?"<<endl; // Pick Fox1 on the board, and move it to this location
            cin >> Fox1FirstX >> Fox1FirstY >> Fox1NewX >> Fox1NewY;
            Duo[1].move(Fox1FirstX,Fox1FirstY, Fox1NewX,Fox1NewY); // move Fox0
            gameBoard[Fox1FirstX][Fox1FirstY] = '.';
            gameBoard[Fox1NewX][Fox1NewY] = 'F';

// ----------------------------------------------------------------------------- Output Board with Foxes Added

    cout<< endl;
    cout<< "Gameboard with the foxes added and moved:"<<endl;
    for (int i = 7; i>=0; i--)
     {
        for (int j =0; j<=7; j++)
        {
            cout << gameBoard[i][j];
            cout << " ";
        }
        cout << endl<<endl;
     }

// -----------------------------------------------------------------------------
}





system("pause");
return 0;

}

Hey that looks similar, if not exact same program project I have. I'm just a bit curious: do you have Mrs. Kaneko? Because you're not supposed to be getting the fox move from standard input. The fox move is to implemented by the program, just to let ya know. ;)

Also the board is supposed to be added by the player in standard input as well.

Yes I do have kaneko, and I know that the board and foxes are supposed to be inputed HOWEVER I am working with what I have so I am sure she will understand that lol. If you have any suggestions on how to add to this please let me know lol.

If you can post all the code you have thus far I can possibly help you out. I have a few hours to spare tonight.

hello

I am currently doing the same project and I wonder if I could have some help with it

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.