Beginner - Chess at C

Joined
Oct 18, 2023
Messages
1
Reaction score
0
Helo,
I'm new to programming, I'm in the first semester of Computer Science. I need to deliver a project by the end of November: developing a complete chess game in just C. I would like to know if anyone has any tips, sources, books, guidance because, honestly, I don't know where to start and the topics I need The teacher hasn't told us yet. Some guidance or a complete code for me to base myself on (I will need to explain my code in detail).
I thank.
 
Joined
Sep 21, 2022
Messages
122
Reaction score
15
Its difficult to write a program that play chess well.

Its easy to write a program that plays chess like a beginner.

All two player board games use the same logic. Chess and tic tac toe are the same.

You have a number of valid moves to choose from. Give each of them a score from 0 (bad) to 1 (good). Play the move with the highest score.

What's the best move?

Use recursion, play a move, turn the board around, ask the same question.

My best move is when my opponent's best reply scores the lowest.

If my move causes my opponent's best next move to score 0.7 then I score my move as 0.3 (1-0.7)

You can't recurse forever, at some point you need to score a move based on just the board.

In the case of chess that would be adding up the value of the pieces, or testing for a check mate.

Just my opinion.
 
Joined
Sep 21, 2022
Messages
122
Reaction score
15
Code:
The general idea:

best_move(player,level)
  B = the other player
  S = 0
  FOR all valid moves
    do move
    IF level = 0
      x = score board
    ELSE
      (x,m)=best_move(B,level-1)
      x = 1-x
    undo move
    IF S < x
      S = x
      M = move
  return (S,M)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top