Explore BrainMass
Share

Chess game in C

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Create table game characters 8x8, where will store THE POSITION OF Figure each
time on this chessboard. The creation of the list must be made with commitment memory. In addition
create structure (struct move) to be used for the registration movements with the elements:
CHAR OVER, char prevpos[2], char nexpos[2], move *next, move *prev. The program, with the
start-up phase, shows the screen menu the following options:

MAIN MENU Thema 1
[N] Start New Game Thema 2
[S] Score Thema 3
[U] Undo Thema 4
[E] End Program
Selection (N, S, U, E):

The program will goes only in the case given valid choice (one of the above mentioned letters),
in any other case will again expects to one new selection. After the execution of a selection
return in the mainly menu. TERMINATES WHEN given E.

Choice N Starts a new game. Firstly make a double connected list Moves with nodes move, where it will be stored in sequence of
moves.Create two stacks black and white, where will be maintained file of pieces of figures that
wins every player. The list black (white) corresponds in the player with black (white) pieces
and are stored the white (blacks) Figures. Afterwards the game begins and the computer asks the
sequence of movements with the way as it is descriped in subjects 3 and 4 at the first work project. You Can use or
your own corresponding code or the proposed solutions of first work where
shape suitably.

For each valid movement, you supplement suitably the elements of one node move and
add in the double connected list, and inform proportionally the table game. If in
final square of movement exists rival piece, it is eaten and removed from the dash (game),
it is registered in stack the player (white or black) and is added node with nexPos= ` - - `. If
piece Figure is the King of opponent, then is not placed in no list and we consider that the player
that makes the movement it Wins: is printed suitable message in the screen and the game terminates. If
exists his own piece Figure, the movement is cancelled and is required to give a valid move. The process is repeated up to
the user types instead of movement the symbol baluster (#), therefore will return in
main Menu.

Choice S will evaluate the existing situation and will elect the winner for the case
that the game terminates without winner (for example when has been agreed concrete biggest duration
game). In order to becomes this, from each stack are removed the Figure pieces, are printed message
description in the screen and are registered the points in the corresponding player, according to the values
that appear in table 1. The player with most points, is the winner and
it is announced in the screen. If there is equal total points, is printed message of draw.

Subject 4: Undo of movements
When is given the choice U in the main Menu, the program asks the player how much movements it wants
it reverses. The figure that is given concerns successive movements, independent player, beginning from
the last one. For the recantation is used the double connected list, from where a-one
movements are described in the screen and are informed suitably the table. Proportionally they become also
changes in the two stacks. Obviously, it should it is recognized in who belongs the movement when
` is eaten' figure piece.

© BrainMass Inc. brainmass.com October 25, 2018, 5:46 am ad1c9bdddf
https://brainmass.com/computer-science/c/chess-game-in-c-433819

Attachments

Solution Preview

Attached is the compete solution C-source code file. There are plenty of comments. The main menu looks ...

Solution Summary

The solution contains a basic immitation of a chess game. The chess board is displayed with letters standing for figures. Movements are not restricted in any direction, but you cannot step on to your own piece. After each move an update board is displayed. There is also an Undo operation available.

$2.19
See Also This Related BrainMass Solution

Chess Game in Dev-C

Program should be done using C language and using Dev-C++
I need main manu as the following

MAIN MENU
(Thema1)
[d] Display Empty Chess Board
(Thema2)
[v] Check Validity of Chess Notation (we use K, E, Q, R, N, B , P.)
THE CELLS ARE a1, a2, a3, a4, a5, a6, a7, a8
b1, b2, b3, b4, b5, b6, b7, b8
c1, c2, c3, c4, c5, c6, c7, c8
d1, d2, d3, d4, d5, d6, d7, d8
e1, e2, e3, e4, e5, e6, e7, e8
f1, f2, f3, f4, f5, f6, f7, f8
g1, g2, g3, g4, g5, g6, g7, g8
So valid moves are Ka1 to Ka8 or Kb1 to Kb8
or Kc1 to Kc8 or Kd1 to Kd8 or Ke1 to Ke8 or Kf1 to Kf8
or Kg1 to Kg8 also valid moves are all moves that K does by using Q, R, N, B or P
A user by pressing "v" gives for example Kb9 which is not valid move he will get a notation on screen "not valid move" . iF HE gives Kb2 then gets on screen "Valid move. Ok"
(Thema3)
[s] Save Moves to a Text File (This selection do the same as the previous but store the moves in a txt file)
(Thema4)
[f] Find Chess Moves in a String (user gives a char string of 30 characters. If he gives more the program keeps the first 30 and it finds valid moves from 30characters . The results should be displayed on screen )
(Thema5)
[e] End Program
Selection [d, v, s, f, e]:

View Full Posting Details