SaifAli JT
SaifAli JT

Reputation: 1

I keep getting these errors and they're not going away. I'm a newbie and this is an easy code

I am making a chess game for my uni project. Up until now, I have only studied if/else, for/while/goto, 1D/2D arrays, pointers, and functions. I can only use these things in my code.

I have written a code and the problem that occurs is here:

When I'm taking input from user as rank-rank addresses, I am trying to store them in an array. I tried using 8 variables for it, but after 3 moves the first ade move resets.

Also, I keep getting this error :

Error 2 error LNK1120: 1 unresolved externals C:\Users\Laptop\Desktop\FinalChess\Debug\FinalChess.exe 1 1 FinalChess

and

Error 1 error LNK2019: unresolved external symbol "int __cdecl gameboard(int,int,int,int,int,int,int,int)" (?gameboard@@YAHHHHHHHHH@Z) referenced in function _main C:\Users\Laptop\Desktop\FinalChess\FinalChess\Source.obj FinalChess

Here is the code:

#include <iostream>
#include <string>
using namespace std;

const int BL = 19;
string boardBorder[BL][BL];
//string *rankFile[8][8];
string swapper;
char sp = ' ';

int gameboard( int, int, int, int, int, int, int, int);

void pieceplace()
{
    for (int ROW = 0; ROW < BL; ROW++)
    {
        for (int COL = 0; COL < BL; COL++)
        {
            if (ROW == 4 && COL>0 && COL<18 && COL % 2 == 0)
                boardBorder[ROW][COL] = 'S';
            if (ROW == 14 && COL>0 && COL < 18 && COL % 2 == 0)
                boardBorder[ROW][COL] = 's';
            if (ROW == 2 && COL == 2 || ROW == 2 && COL == 16)
                boardBorder[ROW][COL] = 'R';
            if (ROW == 16 && COL == 2 || ROW == 16 && COL == 16)
                boardBorder[ROW][COL] = 'r';
            if (ROW == 2 && COL == 4 || ROW == 2 && COL == 14)
                boardBorder[ROW][COL] = 'H';
            if (ROW == 16 && COL == 14 || ROW == 16 && COL == 4)
                boardBorder[ROW][COL] = 'h';
            if (ROW == 2 && COL == 6 || ROW == 2 && COL == 12)
                boardBorder[ROW][COL] = 'B';
            if (ROW == 16 && COL == 12 || ROW == 16 && COL == 6)
                boardBorder[ROW][COL] = 'b';
            boardBorder[2][10] = 'K';
            boardBorder[16][10] = 'k';
            boardBorder[2][8] = 'Q';
            boardBorder[16][8] = 'q';
        }
    }
}

int moves = 1;

void main()
{
    int from[197], from2[197], to[197], to2[197], f[197], f2[197], t[197], t2[197];
    pieceplace();
    gameboard(from[197], from2[197], to[197], to2[197], f[197], f2[197], t[197], t2[197]);
    pieceplace();
    /*for (int i = 1; i <= 8; i++)
    {
    for (int j = 1; j <= 8; j++)
    {
    rankFile[i][j] = &boardBorder[i * 2][j * 2];
    }
    }*/
    for (; moves <= 1972; moves++)
    {
        cout << "\t\tPlayer white's turn : ";
        cout << "Please enter current rank-to-rank address : ";
        cin >> from[moves] >> from2[moves];
        cout << "\n\t\t\t\t\tPlease enter a new rank-to-rank address : ";
        cin >> to[moves] >> to2[moves];

        boardBorder[to[moves] * 2][to2[moves] * 2] = boardBorder[from[moves] * 2][from2[moves] * 2];
        boardBorder[from[moves] * 2][from2[moves] * 2] = " ";

        system("CLS");
        gameboard(from[197], from2[197], to[197], to2[197], f[197], f2[197], t[197], t2[197]);

        moves++;

        cout << "\t\tPlayer black's turn : ";
        cout << "Please enter current rank-to-rank address : ";
        cin >> f[moves] >> f2[moves];
        cout << "\n\t\t\t\t\tPlease enter a new rank-to-rank address : ";
        cin >> t[moves] >> t2[moves];

        boardBorder[t[moves] * 2][t2[moves] * 2] = boardBorder[f[moves] * 2][f2[moves] * 2];
        boardBorder[f[moves] * 2][f2[moves] * 2] = " ";

        system("CLS");
        gameboard(from[197], from2[197], to[197], to2[197], f[197], f2[197], t[197], t2[197]);
    }

    cout << "\n\n\n";
}

int gameboard(int from[197], int from2[197], int to[197], int to2[197], int f[197], int f2[197], int t[197], int t2[197])
{
    system("color F0");

    for (int ROW = 0; ROW < BL; ROW++)
    {
        for (int COL = 0; COL < BL; COL++)
        {
            if (ROW >= 1 && ROW <= 17 && COL == 1 || ROW >= 1 && ROW <= 17 && COL == 17)
            {
                boardBorder[ROW][COL] = "|";
            }
            else if (ROW >= 1 && ROW % 2 == 0 && COL >= 2 && COL % 2 != 0 && ROW <= 17 && COL <= 16)
            {
                boardBorder[ROW][COL] = "|";
            }
            else if (ROW >= 1 && ROW % 2 != 0 && COL >= 2 && COL % 2 != 0 && ROW <= 17 && COL <= 16)
            {
                boardBorder[ROW][COL] = "+";
            }
            else if (ROW >= 1 && ROW % 2 != 0 && COL >= 2 && COL % 2 == 0 && ROW <= 17 && COL <= 16)
            {
                boardBorder[ROW][COL] = "-";
            }
            else
                boardBorder[ROW][COL] = " ";
        }
    }
    int siders = 1, side = 1, upper = 1, up = 1;
    int mov = 1;

    pieceplace();

    boardBorder[to[mov] * 2][to2[mov] * 2] = boardBorder[from[mov] * 2][from2[mov] * 2];
    boardBorder[from[mov] * 2][from2[mov] * 2] = " ";
    mov++;
    boardBorder[t[mov] * 2][t2[mov] * 2] = boardBorder[f[mov] * 2][f2[mov] * 2];
    boardBorder[from[mov] * 2][from2[mov] * 2] = " ";

    for (int ROW = 0; ROW < BL; ROW++)
    {
        for (int COL = 0; COL < BL; COL++)
        {
            if (ROW == 0 && COL == 1 || ROW == 18 && COL == 1)
            {
                cout << "  ";
            }
            if (ROW >= 2 && ROW <= 16 && ROW % 2 == 0 && COL == 1)
            {
                cout << siders++;
            }
            if (ROW >= 2 && ROW <= 16 && ROW % 2 == 0 && COL == 18)
            {
                cout << side++;
            }
            if (ROW == 0 && COL >= 2 && COL <= 18 && COL % 2 == 0)
            {
                if (upper < 9)
                    cout << "\b" << upper++;
            }
            if (ROW == 18 && COL >= 2 && COL <= 18 && COL % 2 == 0)
            {
                if (up < 9)
                    cout << "\b" << up++;
            }
            if (COL == 0)
                cout << endl;



            if (COL == 1 && ROW >= 1 && ROW <= 17 && ROW % 2 == 0)
            {
                cout << boardBorder[ROW][COL];
            }
            else
            {
                cout << " " << boardBorder[ROW][COL];
            }
        }
    }
    cout << "\n\n\t\t\t\bBoth Players must use the rank-to-rank address to choose or move a piece.\n\n";
    return 0;
}

Upvotes: 0

Views: 39

Answers (1)

jkb
jkb

Reputation: 2450

You've declared a function that takes ints as parameters:

int gameboard( int, int, int, int, int, int, int, int);

You've defined a 2nd function that takes arrays of ints:

int gameboard(int from[197], int from2[197], int to[197], int to2[197], int f[197], int f2[197], int t[197], int t2[197])

In main you are attempting to call the function that takes ints

gameboard(from[197], from2[197], to[197], to2[197], f[197], f2[197], t[197], t2[197]);

(The numbers in the square brackets are subscripts, not sizes.)

You have not actually defined the version of the function that takes int arguments and your attempt to call it results in linker errors.

Also, you are accessing elements of the arrays outside of their valid ranges. For example, from[197] references the 198th element of a 197-element array.

Upvotes: 1

Related Questions