Algorithm for judging the legality judgment in China's chess (with the algorithm written by TC2.0)

zhaozj2021-02-11  203

For Chinese chess, each word has its own rules, and the so-called unregulated is not a square.

Chessboard is set first, A: Array [1..10] [1..9] of mapstruct; is a two-dimensional array, each unit full-customized chessboard structure does not define a chess word structure

Int Stepjudge (int Oldx, int in)

/ * Oldx, Oldy chess word original location * // * Oldx, oldy chess new location * // * Judgment from the original position to the new position of the legitimacy * / {int index, count = 0; int NOx, Noy; int = X, Y, X1, X2, Y1, Y2; BYTE CHESSID; / * Which of the chess characters, there is RED, Blue, None three values ​​* / chessid = map [oldx] [Oldy] .id; if (ChessID) == None) return 0; if (Oldx == NOWX && loty ======) return 0; if (nowX> 8 || NOWX <0 || NOWY <0 || NOWY> 9) Return 0; NOx = NoWX-Oldx; Noy = no-oldy; switch (map [oldx] [oldy] .num) {case 0: / * headercapital * / will or handsome {ix (map [noWX] [nowy] .num == 0 && map [now] ] .Id! = None && lotx == no = no = = = = = = = = = = nowy; if (NOWY 1 || ABS (NOY> 1 || ABS (NOX) == 1 && ABS (NOY) == 1) Return 0; if (NOWY> 2 &&own <7 || NOWX <3 || NOWX> 5) Return 0; Break;} Case 14: Case 15: / * Genaral * / Car {IF (ABS (NOX)! = 0 && ABS (NOY)! = 0) Return 0; IF (ABS (NOx)> 1 && NoY == 0) {x1 = OLDX; x2 = no (nowx 1) {Y1 = Oldy; Y2 = NoY; if (nowy

IF (ABS (NOX) == 2 && Map [Oldx NOx / 2] [Oldy] .ID! = none) Return 0; Break;} else return 0;} case 12: case 13: / * gun * / gun {IF (ABS (NOx)> 0 && ABS ((NOY)> 0) RETURN 0; IF (ABS (NOX)> 0 && NoY == 0) {x1 = OLDX; x2 = no (nowx 0) {y1 = Oldy; Y2 = nowy; if (nowy 1) returnograph; ix; Break;} case 3: case 4: / * minister * / icon or phase {IF (ABS (NOX)! = 2 || ABS (NOY)! = 2) Return 0; Else IF (MAP [OLDX NOx / 2 ] [Oldy NOY / 2] .id! = none) Return 0; if (nowy == 0 || NOWY == 4 || NOWY == 5 || NOWY == 9) IF (nowX == 2 || Nowx == 6) Break; if (nowy == 2 || NOWY == 7) IF (nowX == 0 || NOWX == 4 || NOWX == 8) Break;} case 1: case 2: / * Shi * / 或 {{IF (ABS (NOX)! = 1 || ABS (NOY)! = 1) Return 0; IF (NOWY> 2 &&own <7 || NOWX <3 || NOWX> 5) Return 0; Break;} case 5: Case 6: Case 7: Case 8: Case 9: / * Soldier * / soldier or paw {ix (ABS (NOX)> 0 && ABS (NOY)> 0) Return 0; if (chessid == Green && Greenchess [0]. Y < 3 || Chessid == Red && Redchess [0] .y <3) {if (Oldy> 4) {if (NOx == 0 && no! = 1) Return 0; if (ABS (NOX)! = 1 && noy == 0) Return 0;} IF (Oldy <5) IF (NOX! =

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

New Post(0)