A winter holiday written five daughter

xiaoxiao2021-03-05  24

[Problem Description]

Realize a simple two-person battle five-child chess game, automatically judge the victory. At the same time, the thinking time and drop position of each step are recorded. And at each game, some heuristic information can be provided to the players.

[basic requirements]

On the interface, the necessary features are displayed, and most of the rest are placed in the menu. For such chess games, timing and scoring functions are generally an essential part, and there are also players' horizontal display, the highest record display, and so on.

For reference data structures and algorithms]

The data structure only needs one two-dimensional array. For the integer array cell [x] [Y], the abscissa of the mouse position is recorded, Y records the ordinate of the mouse position, and the unit 0, 1, 2 indicates that it is not selected, by Player A is selected by player B. Corresponding, the new game is actually used to assign the entire array to 0, and the player losing the winning judgment is the left, right, upper, down, left, left, upper right, bottom right, right search. If the adjacent 5 array cells are identical and not zero, the determination of the corresponding players will win.

[Event recommendation]

You can try to achieve human-machine battle. At this point, for each step of the machine, you need to consider the optional best way to take care of the current situation, which involves the heuristic search algorithm.

problem analysis

Write a five-child game based on the problem.

Systematic analysis

This software has the function of choosing the function of everyone who fights against the battle. It can judge the winning and win, and can calculate the summary of the game, how many chess pieces can be calculated.

1, the number of things Whitewin, Blackwin

2, chess pieces IWHITE, IBLACK

3, everyone fights tag = 0, human machine battle tag = 1

4, judge the win loss iswin ()

5, artificial intelligence DOAI ()

programming

1 Using the contents of cdocument to include data, use the contents of the cView to display

2 Use ONLBUTTONDOWN to display graphics and change data

3 In CDocument SETPOINT () calls Onai () to set up the new computer to get the data point, where ONAI's algorithm is divided, up and down, left and right, the upper left right upper four options, while setPoint () It is to choose from five points to a point, when five points, when four points, second .......... So push until a point.

4 Findfir () Looking for the first data, reduce space tree

5 Findlast () find the last data

6 CVIEW in init () is used to initialize the graphics and use onDraw () to draw

7 use lbuttondown () to draw graphics

8 DrawWhite used to draw white chess

9 drawblack is used to draw black chess

10 Call iswin () when judged to win, if the victory is initialized the graphical onDraw ()

11 onfilenew2 () New Chessboard

Some main algorithms (some unnecessary parts have been simplified)

Void CFiveView :: ONLBUTTONDOWN (Uint Nflags, Cpoint Point)

{

IF (((Point.x <25) || (Point.x> (MAXX 1) * 25))

|| ((Point.Y <25) || (Point.y> (MAXY 1) * 25)))))) // Take a look at the chess there

MessageBox ("You can't play chess here");

IF ((POINT.X> = (i 1) * 25) && (Point.x <(i 2) * 25)

&& (Point.Y> = (J 1) * 25) && (Point.Y <(j 2) * 25))))

{

IF (PDOC-> Cell [I] [J]! = 0)

MessageBox ("You can't play chess here");

IF (PDOC-> Blacknum <= pdoc-> whiteum) // black chess {

DrawBlack (PDC);

}

ELSE / / white chess

{

DrawWhite (PDC);

}

}

Bool cfivedoc :: Iswin (int I, int J) // Victory condition

{

IF (((((((((((i-5 <0) && (i 5> maxx))) / / Reduce search space

For (Tempi = 0; Tempi <5; Tempi ) //

{

For (Tempj = 0; Tempj <5; Tempj )

{

IF ((Cell [I] [J] == Cell [i-Tempi Tempj] [J])! = 0)

K ;

}

IF (k == 5) Return True;

K = 0;

}

Cpoint cfivedoc :: setpoint ()

{

IF ((nowPoint.x == - 1) && (nowPoint.y == - 1))

{

PNOW.X = 7;

PNOW.Y = 8;

Return PNOW;

}

IF ((PNOW = DOAI (PFIR, Plast, 5, 2, True)! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 4, 2, False)! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (Pfir, Plast, 5, 3, True)! = noPoint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 4, 3, False))! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 4, 2, True)! = noPoint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (Pfir, Plast, 3, 2, False)! = noPoint

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (Pfir, Plast, 4, 3, True)! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 3, 3, False))! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 3, 2, True)! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, PLAST, 2, 2, FALSE))! = noint) IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 3, 3, True)! = noPoint

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (Pfir, Plast, 2, 3, False)! = noPoint

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 1, 2, False)! = noint)

IF ((pNow.x

Return PNOW;

IF ((PNOW = DOAI (PFIR, Plast, 1, 3, False)! = noPoint)

IF ((pNow.x

Return PNOW;

Return PNOW;

}

Cpoint Cfivedoc :: Doai (Cpoint Pfir, Cpoint Plast, Int Length, Int Color, Bool Havefree)

// pfir is the first number, Plast is the last number, Length is the length to search, and Color is black and white, and Havefree is a blank

{

For (i = 0; i

For (j = 0; j

{

IF (J Length

{

For (Tempj = 0; Tempj

{

IF (Cell [I] [J Tempj] == Color)

M ;

ELSE IF (Cell [i] [J TEMPJ] == 0)

{

Pblank.x = i;

PBLANK.Y = J TEMPJ;

}

IF ((M == Length) && (! Havefree))

{

IF (Cell [I] [J-1] == 0)

{

PNOW.X = i;

PNOW.Y = J-1;

Return PNOW;

}

IF (Cell [I] [J Tempj 1] == 0)

{

PNOW.X = i;

PNOW.Y = J TEMPJ 1;

Return PNOW;

}

IF ((M == Length-1) && (Havefree) // has space

&& (PBLANK.Y> J-1) && (Pblank.y

{

PNOW = pblank;

Return PNOW;

}

}

m = 0;

}

}

Data transfer process:

ONFilenew2 ()

|

ONLBUTTONDOWN () -> PDOC-> nowPoint

|

CDocument :: setPoint () -> Cell [] [], NOWPOINT

|

Findfir () -> PFIR

|

FIRDLAST () -> Plast

|

Onai () -> PNOW |

Draw ()

|

Iswin () -> nowi, nowj-n return

| --Y

OnDraw ()

|

Init ()

software test:

Black box test __ uses it to play games while testing.

White box test __ Check the data inside, started due to not initialization, and the resulting data error

转载请注明原文地址:https://www.9cbs.com/read-34883.html

New Post(0)