Thread: Help in checkers game!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2022
    Posts
    3

    Help in checkers game!

    Please help me i have this due soon,also here is my source code for the game, does anybody know what i should do to make the pieces move? thank you.
    Code:
    #include <stdio.h>
    #include <Windows.h>  //include the windows API to print unicode
     //allows print unicode
    
    
    //Sets-Up Checker Pieces by giving a value in a multidimensional array.
    void initializeBoard(int board[8][8])
    {
    int i, j, k;
        
        for(i = 1; i < 9; i++)
        {
            for(j = 1; j < 9; j++)
            {
                if(((i == 6)&&(j%2 == 1))||((i == 7)&&(j%2 == 0))||((i == 8)&&(j%2 == 1))) //Player 1 Pieces; valid square value is changed to 1
                {
                    board[i][j] = 1;
                }            
                else if(((i == 1)&&(j%2 == 0))||((i == 2)&&(j%2 == 1))||((i == 3)&&(j%2 == 0))) //Player 2 Pieces; valid square value is changed to 2
                {
                    board[i][j] = 2;
                }   
                else if((i + j)%2 == 1) //Checks all Valid Squares and value is set to 3
                {
                    board[i][j] = 3;
                }          
                else
                {
                    board[i][j] = 0;
                }
            }
        }
    }
    void printBoard(int board[8][8])
    {
        int i, j, k;
        int a = 0; //piece number for black
        int b = 13; //piece number for white
        //print column number
        
        for(k = 1; k != 9; k++)
        {
            printf("  %d ",k);
        }
        //print board
        printf("\n+---+---+---+---+---+---+---+---+\n"); //top row divider
        for(i = 0; i <9; i++) //prints row with i being the number of rows
        {
            for(j = 0; j <9; j++)//prints column with j being the number of rows
            {
                if(board[i][j] == 1)
                {
                    //spacing issues
                    a += 1; 
                    if(a < 10) //if a single digit print piece with space
                    {
                        printf("|D%d ", a);
                    }
                    else //if not single digit print piece without space
                    {
                        printf("|D%d", a); 
                    }
                }
                else if(board[i][j] == 2)
                {
                    //spacing issues
                    b -= 1; 
                    if(b < 10) //if a single digit print piece with space
                    {
                        printf("|L%d ", b);
                    }
                    else //if not single digit print piece without space
                    {
                        printf("|L%d", b); 
                    }
                }
                else if(board[i][j] == 3)
                {
                    printf("| â–  ");
                }
                else
                {
                    printf("|   ");//print a column
                }
            }
            printf("| %d", i); //outer right side border with row numbers
            printf("\n"); //new line to signify new row
            printf("+---+---+---+---+---+---+---+---+\n"); //row divider
        }
    }
    int main()
    {
        SetConsoleOutputCP(CP_UTF8);
        int board[8][8]; //board
        initializeBoard(board);
        printBoard(board);
        return 0;
    }
    Last edited by helpmepls123; 12-02-2022 at 04:27 AM. Reason: Different code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chekers Game GIT checkers
    By sveyda in forum C Programming
    Replies: 0
    Last Post: 04-25-2014, 03:32 AM
  2. Checkers game
    By Aeoskype in forum C++ Programming
    Replies: 11
    Last Post: 05-12-2013, 01:03 PM
  3. Trying to make a checkers game..
    By Luminous Lizard in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2011, 12:04 PM
  4. C++ Checkers Game
    By SnS CEO in forum C++ Programming
    Replies: 9
    Last Post: 09-07-2005, 01:21 AM
  5. IDEA: Checkers game
    By confuted in forum Contests Board
    Replies: 0
    Last Post: 06-28-2003, 03:25 PM

Tags for this Thread