Question

I have to make a Reversi game in C++ where 2 algorithms play against eachother and I do not know how to even start it.

In this project you are required to:
1. Implement Reversi for a board size of n x n where 4 ≤ n ≤ 16 and n is always even.
2. Implement two different algorithms that will play Reversi against each other e.g. an algorithm that randomly chooses a valid move may be one of your algorithms.

You are required to develop a computer program in C++ that allows two different algorithms to compete against each other in a game of Reversi. Your code must meet the following specifications:
• Read in a list of numbers specifying board sizes from a file. • Every game must begin in the starting configuration as seen in figure 1. • Algorithm 1 will take alternating turns with algorithm 2 at placing their markers in the grid. • A marker cannot overwrite an already filled position in the grid. • No global variables may be used - this will result in failing the project with FCOM. • The list of moves made by each algorithm must be stored to an output file.

This in Figure 1:

1234

Example of input:

4, 4

Example of output:

size = 4 (r=row, c=column)

r0c1 alg1 , r1c1

r0c0 alg2 , r1c1

r1c0 alg1 , r1c1

r2c0 alg2 , r1c0 r2c1

r3c1 alg1 , r2c2

r2c3 alg2 , r2c2

r3c2 alg1 , r2c2

r0c3 alg2 , r1c2

r1c3 alg1 , r1c2 r2c3

r0c2 alg2 , r0c1 r1c1

r3c0 alg1 , r2c1

r3c1 alg2 , r2c1

alg1 = 7

alg2 = 9

win = alg2

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<fstream>
#include <string>
#include<string>
#include <iostream>
using namespace std;

const int NUM_ROWS = 8, NUM_COLS = 8;
int determine_game_type_new_or_existing();
void initialize_game_board(int gb [][NUM_COLS]);
void display_gameboard_row(unsigned int rownum, int gb [][NUM_COLS]);
void display_gameboard(int gb [][NUM_COLS]);
void display_cell_top();
void display_cell_side(char cell_middle);
int main()
{
        int player_choice = 0;
        int gameboard [NUM_ROWS][NUM_COLS];
        int player, opponent;
        player_choice = determine_game_type_new_or_existing();  
        switch (player_choice)
        {
                case 1:
                        {
                                initialize_game_board(gameboard);
                                break;
                        }
                case 2:
                        
                                exit (0);
            case 3:
                        {
                                ifstream infile;
                                string rules;
                                infile.open("Rules.txt");
                                infile >> rules;
                                cout << rules << endl << endl;
                                infile.close();
                                break;
                        }
                default:
                        {
                                cout << "Invalid choice!\n\n";
                                exit (1);
                                break;
                        }
        }

        display_gameboard(gameboard);
        int row, col;
        cout << "Make your move.\n\n"
                 << "Row: ";
        cin >> row;
        while (row < 0 && row > 7)
        {
                cout << "Please enter a valid move between 0-7.\n";
                cout << "Make your move.\n\n"
                 << "Row: ";
                cin >> row;
        }
        cout << endl << endl
                 << "Column: ";
        cin >> col;
        while (col < 0 && col > 7)
        {
                cout << "Please enter a valid move between 0-7.\n";
                cout << "Make your move.\n\n"
                 << "Column: ";
                cin >> col;
        }
        return 0;
}

int determine_game_type_new_or_existing()
{
        int the_answer = 0;
        cout << "Welcome to Othello!\n"
                 << "-----------------------\n\n";
        do
        {
                //Ask the question
                cout << "1. New game\n"
                         << "2. Existing game\n"
                         << "3. Rules\n"
                         << "4. Quit\n\n"
                         << "Enter your choice: ";
                cin >> the_answer;
                cout << endl << endl;
        }while (the_answer != 1 && the_answer != 2);
        return the_answer;
}
void initialize_game_board(int gb[][NUM_COLS])
{
        //This is a nested loop to make sure every cell is empty
        //Cell Codes: 0 = empty, 1 = white piece, 2 = black piece
        for (int i = 0; i < NUM_ROWS; i++)
        {
                for (int j = 0; j < NUM_COLS; j++)
                gb[i][j] = 0;
        }
        gb[3][3] = 1;//Put down white piece
        gb[4][4] = 1;//Put down white piece
        gb[3][4] = 2;//Put down black piece
        gb[4][3] = 2;//Put down black piece
}

void display_gameboard(int gb [NUM_ROWS][NUM_COLS])
{
        for (unsigned int num = 0; num < NUM_ROWS; num++)
        {
                cout << "     ";
                display_gameboard_row(num, gb);
        }

        cout << "     ";
        for(unsigned int num = 0; num < NUM_COLS; num++)
                display_cell_top();//Displays a horizontal line
        cout << '+' << endl;
}
void display_gameboard_row(unsigned int rownum, int gb [NUM_ROWS][NUM_COLS])
{
        for (unsigned int num = 0; num < NUM_COLS; num++)
                display_cell_top();//Displays a horizontal line
        cout << '+' << endl;

        cout << "     ";
        for (unsigned int num = 0; num < NUM_COLS; num++)
        {
                display_cell_side(' ');//Displays a vertical line
        }
        cout << '|' << endl;

        cout << "     ";
        for (unsigned int col = 0; col < NUM_COLS; col++)
        {
                //char game_piece;//Either space, W or B
                if ( gb[rownum][col] == 0 )
            display_cell_side (' ');
        else if ( gb[rownum][col] == 1 )
            display_cell_side ('W'); 
        else if ( gb[rownum][col] == 2 )
            display_cell_side ('B'); 
        else
        {
            cout << "An internal error has occurred." << endl;
            exit (2);
        }
        }
        cout << '|' << endl;

        cout << "     ";
        for (unsigned int num = 0; num < NUM_COLS; num++)
                display_cell_side(' ');//Displays a vertical line
        cout << '|' << endl;
}

void display_cell_top()
{
        string cell_top = "+------";
        cout << cell_top;
}

void display_cell_side(char cell_middle)
{
        string cell_left_side = "|   ";
        //string cell_middle = " ";
        string cell_right_side = "  ";
        cout << cell_left_side << cell_middle << cell_right_side;
}
Add a comment
Know the answer?
Add Answer to:
I have to make a Reversi game in C++ where 2 algorithms play against eachother and I do not know ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • C programming language Purpose The purpose of this assignment is to help you to practice working...

    C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...

  • You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's...

    You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's Life is played on a matrix of cells, kind of like a chess board but theoretically extending infinitely in every direction. Each individual cell in the matrix can either be alive or dead. A live cell in the matrix is shown in our simulation by printing an asterisk (*) to the screen. A dead cell is shown by leaving that area of the matrix...

  • Do the following project: Following is the file to be programmed in Linux kernel. Run this...

    Do the following project: Following is the file to be programmed in Linux kernel. Run this program. Include the screenshot of the results. Multi threaded Sorting Application Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sub list using a sorting algorithm of your choice. The two sub lists are then merged by a third thread—a...

  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

  • C++ Programz

    Program 0 (50%): In many computer science courses, when you study sorting, you also study “runtime” - and it can be confusing to understand when you first see it.  For example, they say that BubbleSort “runs in O(n2)”  time (pronounced “Big-Oh of n-squared") - but what does that mean?  For simplicity, it means if you have n elements, the worst it could run would be n2 low-level computer operations (like comparisons, assignment statements and so on).  For example, if we...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; cl...

    //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; class googlePlayApp { private: string name; double rating; int numInstalls; int numReviews; double price;    public: googlePlayApp(string, double, int, int, double); ~ googlePlayApp(); googlePlayApp();    string getName(); double getRating(); int getNumInstalls(); int getNumReviews(); string getPrice();    void setName(string); void setRating(double); void setNumInstalls(int); void setNumReviews(int); void setPrice(double); }; googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT