Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6696603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:21:40+00:00 2026-05-26T06:21:40+00:00

I am currently writing a checker program which uses alpha-beta pruning and a heuristic

  • 0

I am currently writing a checker program which uses alpha-beta pruning and a heuristic to play the game. I am attempting to print out the board at evaluation of the board and I am running into problems getting it to work. My teacher gave us all the code we need to run the program minus the evaluation function and the alpha-beta pruning function. The method for printing the board is in a different class than the methods for finding the best move for the checker game.

Below are par of the search function class header (it doesn’t include all of the method calls) and the evalBoard method which is where we want to print the board

 double evalBoard1(State *state) {
      int x, y;
      double rval = 0.0;
      double rval2 = 0.0;
      evals++;
      for (x = 0; x < 8; x++)
           for (y = 0; y < 8; y++) {
                if (x % 2 != y % 2 && !empty(state->board[y][x])) {
                     if (king(state->board[y][x])) { /* King */
                          if (((state->board[y][x] & White) && !player1) 
                                  || (!(state->board[y][x] & White) && player1))
                               rval += 2.0;
                else
                    rval2 += 2.0;
                } else if (piece(state->board[y][x])) { /* Piece */
                      if (((state->board[y][x] & White) && !player1)
                             || (!(state->board[y][x] & White) && player1))
                           rval += 1.0;
                      else
                           rval2 += 1.0;
                }
            }
       }
     state->PrintBoard(); //should print the board
     fprintf(stderr,"Value = %g\n",rval); //prints the evaluation of that board
     if(rval <= 0.0) return -10000.0;
     if(rval2 <= 0.0) return 10000.0;
     return rval - rval2;
}

 #ifndef COMPUTER_H
 #define COMPUTER_H

 #define Empty 0x00
 #define Piece 0x20
 #define King 0x60
 #define Red 0x00
 #define White 0x80

 #define number(x) ((x)&0x1f)
 #define empty(x) ((((x)>>5)&0x03)==0?1:0)
 #define piece(x) ((((x)>>5)&0x03)==1?1:0)
 #define king(x) ((((x)>>5)&0x03)==3?1:0)
 #define color(x) ((((x)>>7)&1)+1)

 #define Clear 0x1f

 typedef struct{
     int player;
     char board[8][8];
     char movelist[48][12];  
     int numLegalMoves;
 }State;
 //all method calls occur after here
 #endif

Below this is the checkers.h file (it doesn’t not include all other method calls beside PrintBoard()) and the checkers.c file (only includes the printBoard method and the Struct square call)

struct Square square[16][16];


void PrintBoard() {
int board[8][8];
int x,y;
char ch = 127;

for(y=0; y<8; y++)
{
   for(x=0; x<8; x++)
   {
       if(x%2 != y%2) {
           if(square[y][x].state) {
               if(square[y][x].col) 
               {
                  if(square[y][x].state == King) board[y][x] = 'B';
                  else board[y][x] = 'b';
               }
               else
               {
                  if(square[y][x].state == King) board[y][x] = 'A';
                  else board[y][x] = 'a';
               }
           } else board[y][x] = ' ';
       } else board[y][x] = ch;
       printf("%c",board[y][x]);
   }
   printf("\n");
}
}


 #ifndef CHECKERS_H
 #define CHECKERS_H

 #define Empty 0
 #define Piece 1
 #define King 2

 #define HUMAN 1
 #define COMPUTER 2

 struct Square {
         Widget widget;
         int val;
         int state;
         int col;
         int hilite;
 };

 void PrintBoard();
 #endif

I attempted to just call state->PrintBoard() but the program couldn’t recognize the call. I also tried adding a Square struct to the State struct in the computer header file but that also created an error. I also created a new PrintBoard method in the computer.c file but it wouldn’t know which color state was in each square. Any help would be appreciated and I can post more code that I have if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:21:40+00:00Added an answer on May 26, 2026 at 6:21 am

    With the way your code is currently written, PrintBoard is a stand-alone function as it should be in a C-program … it’s not a method of the State class like you would have with C++. Therefore if you want to call state->PrintBoard(), you are going to have to make that function a method of the State class and use a C++ compiler to compiler your program… otherwise, if you want to keep it as a stand-alone function and use a C-compiler, you’re going to have to add a State* argument to PrintBoard, and then call it like PrintBoard(state).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a TYPO3 extension which is configured with a list of tt_content
I am in the process of writing a spell checker program. basically i split
I am writing a simple task planner and reminder using Qt which will play
I am currently writing a WPF application which does command-line argument handling in App.xaml.cs
Im currently writing my bachelor thesis with latex and using TexnicCenter. I want to
Our company is currently writing a GUI automation testing tool for compact framework applications.
I am currently writing a simple, timer-based mini app in C# that performs an
I am currently writing a small calendar in ASP.Net C#. Currently to produce the
I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP
I'm currently writing an interface to allow applications to send exception data to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.