My black and white chess

xiaoxiao2021-03-05  28

#include

#include

/ * The program has used a lot of global variables, which is also no way, because these variables take up in the program runtime, in order to unnecessary function parameter interface, make many variables to global variables * /

/ * All 1 means Player1, 2 represents Player2, * /

/ * Program adds config, you can define key settings yourself

Config is quite independent,

I store a key in 2 char.

Default key setting: 0 1 2 3 4 5 6 7 8 9

Function other party confirms that the upper right side of the right person registred chess, the other party's regrets, the other party's advice

P1 W a S D h - r * Enter

P2 Enter the left right - h * r

* /

/ * Use for global variables:

QP [] []: Store the image you need to print, easy to print

CMP [] []: Storage Key Settings

strDef [] []: Default Key Settings

QPS [] []: Real chessboard, 0 empty 1 p1 2 p2

LSQP [] []: Where can be lower than 0 can't be used to calculate whether it is ended and printed

qPold [] [] [] stores old chessboard, regrets can use infinite regp, I think I don't want to regret it

X [] Y [] The cursor is to move to the location, for example, I am at 5, 5 when the other side is starting at 5, 5

Xold [] yold [] stored old cursor position // seems to be useless, it is not very good to change

XN [] The number of energy, the two sides end is 0, the number of statistics

M [] disk number

* /

/ * Program shows where you can, if you feel bad, remove the statement about refresh3 (), you will line * /

Char qp [25] [26], cmp [3] [21], strdef [3] [21] = {{0}, {' ', 0, 'w', 0, 'a', 0, ' s', 0, 'd', 0, 'h', 0, '-', 0, 'r', 0, '*', 0, '/ r', 0, 0}, {'/ R' 0, 0, 72, 0, 75, 0, 80, 0, 77, '-', 0, 'h', 0, '*', 0, 'R', 0, ' ', 0, 0 }};

INT QPS [10] [10], LSQP [10] [10], qpold [3] [10] [10], x [3], y [3], xn [3], yold [3], xn [ 3], M [3] = {0,0,0};

INT P, P1; / * P For the current Player, P1 is the other party * /

Void CSQP (Void) / * Initialized Chessboard * /

{INT I, J;

For (i = 0; i <25; i ) for (j = 0; j <25; j ) qp [i] [j] = ''; / * qp [] [] housing initialization * /

For (i = 0; i <25; i ) qp [i] [25] = 0;

For (i = 0; i <25; i = 3)

{for (j = 0; j <24; j = 3)

{qp [i] [j] = ' '; QP [i] [j 1] = '-'; QP [i] [j 2] = '-';}

QP [i] [j] = ' ';

}

For (i = 1; i <23; i = 3) for (j = 0; j <25; j = 3) QP [i] [j] = qp [i 1] [j] = '|';

For (i = 0; i <10; i ) for (j = 0; j <10; j ) {QPS [i] [j] = 0; QPOLD [P] [i] [j] = 0;} QPS [4] [4] = QPS [5] [5] = P1; / * Put your chess pieces * /

QPS [4] [5] = QPS [5] [4] = P;

QPold [P] [4] [4] = qPold [P] [5] [5] = P1; / * Initialized registered chess board // is actually no * /

QPOLD [P] [4] [5] = qPold [P] [5] [4] = P;

XOLD [P1] = 6; Yold [P1] = 5;

X [1] = 5; y [1] = 4;

}

INT refresh1 (int player) / * Calculates the chess pieces from a given PLAYER, placed in LSQP [] [], returns the number below * /

{INT I, J, M, N, A, B, AOPLAYER;

AOPLAYER = -Player 3;

For (i = 0; i <10; i )

For (j = 0; j <10; j )

LSQP [i] [j] = 0;

For (i = 1; i <9; i )

For (j = 1; j <9; j )

{

IF (QPS [I] [J]) Continue;

FOR (m = -1; m )

FOR (n = -1; n <2; n )

{

A = i m; b = j n;

IF (QPS [A] [B] == AOPLAYER)

{

While (QPS [A = M] [B = n] == AOPLAYER);

IF (QPS [A] [B] == Player) LSQP [I] [J] = 1;

}

}

}

m = 0;

For (i = 1; i <9; i )

For (j = 1; j <9; j )

M = LSQP [i] [j];

Return M;

}

INT HMQ (INT Player) / * Return to a given Player number * /

{

INT I, J, N = 0;

For (i = 1; i <9; i )

For (j = 1; j <9; j )

IF (QPS [I] [J] == Player)

N ;

Return n;

}

Void refresh3 () / * put the current Player can be placed in QP [] [], used to print * /

{

INT I, J, M, N;

For (i = 1; i <9; i )

For (j = 1; j <9; j )

{

IF (! lsqp [i] [j])

CONTINUE;

M = I * 3-2;

N = j * 3-2;

QP [M] [N] = QP [M 1] [N 1] = '//';

QP [M 1] [N] = QP [M] [N 1] = '/';

}

}

Void refresh2 () / * Print the chess pieces, put it in QP [] [], you want to use the in Refresh3 (), otherwise covering the place under printing * /

{

INT I, J, M, N;

For (i = 1; i <9; i )

For (j = 1; j <9; j )

{

M = I * 3-2;

N = j * 3-2;

QP [M] [N] = QP [M] [N 1] = QP [M 1] [N] = QP [M 1] [N 1] = QPS [i] [j] == 1 ? ' ': QPS [i] [j]? 'o': '';}

}

Void HQ_ (int * HQ) / * Remelling Chess Processing, who regrets chess, current Player, copy qld [] [] [] to qps [] [] * /

{INT I, J;

P = * hq; p1 = -p 3;

* HQ = 0;

For (i = 1; i <9; i ) for (j = 1; j <9; j ) QPS [i] [j] = qPold [p] [i] [j];

X [P] = XOLD [P]; Y [P] = Yold [P];

Refresh1 (P1); Refresh1 (P);

}

Char Tranf (Char CH1, CHAR CH2) / * compares the acceptable characters and key position settings, return characters 0 ~ 9 error Returns 0 * /

{INT I;

IF (! CH1)

{for (i = 0; i <10; i )

{IF (CH2 == CMP [P] [i * 2 1]) {CH1 = I 48; Break;}}

IF (i == 10) CH1 = 0;

}

Else {for (i = 0; i <10; i )

{IF (CH1 == CMP [P] [i * 2]) {CH1 = i 48; Break;}}

IF (i == 10) CH1 = 0;

}

Return CH1;

}

CHAR SURE () / * Confirmation confirmation, * /

{Char CH1, CH2;

GotoxY (26, 4); Clreol (); Printf ("Are you SURE?");

CH1 = getChe (); if (! CH1) CH2 = getChe ();

CH1 = TRANF (CH1, CH2);

Return CH1;

}

Void Play (int X1, int y1) / * is confirmed before the X1, Y1 under the underfloction of the sub-off * /

{INT I, J, M, N, A, B, X2, Y2;

X2 = x1 / 3; y2 = y1 / 3; x [p1] = x2; y [p1] = Y2;

XOLD [P] = X [P]; Yold [P] = Y [P];

For (i = 1; i <9; i ) for (j = 1; j <9; j ) qPold [p] [i] [j] = qps [i] [j];

For (i = -1; i <2; i ) for (j = -1; j <2; j )

{a = m = x2 i 1; b = n = y2 J 1;

IF (QPS [B] [A] == P1)

{

While (QPS [B = J] [A = I] == P1);

IF (QPS [B] [A] == P) for (; (m-a) || (N-B); M = I, N = J) QPS [N] [M] = P;

}

}

QPS [Y2 1] [x2 1] = P;

}

Void Go () / * Show who is down * /

{gotoxy (26, 4); Clreol ();

Printf ("Player% D GO!", P);

}

Void Printhead () / * Print information, how many children, win a few caps, etc. * /

{

gotoxy (26, 1);

Printf (" OO / N");

gotoxy (26, 2);

Printf (" Player1:% 2D OO Player2:% 2D / N", HMQ (1), HMQ (2));

gotoxy (26, 3);

Printf ("Player1: Player2% D:% D / N", M [1], M [2]);

}

Void Unmake (CHAR STR [15], int player) / * config part extracts Player settings from the key bit setting * /

{INT I;

For (i = 0; i <7; i ) STR [i] = cmp [player] [i 2];

STR [8] = CMP [Player] [10];

STR [9] = CMP [Player] [11];

STR [10] = CMP [Player] [14];

STR [11] = CMP [Player] [15];

STR [12] = CMP [Player] [18];

STR [13] = CMP [Player] [19];

}

Void make (CHAR STR [15], int player) / * config parts player set these settings in the key bit setting, otherwise white settings * /

{INT I, AOPLAYER; AOPLAYER = -Player 3;

For (i = 0; i <7; i ) CMP [Player] [i 2] = STR [i];

CMP [Player] [10] = STR [8];

CMP [Player] [11] = STR [9];

CMP [Player] [14] = STR [10];

CMP [Player] [15] = STR [11];

CMP [Player] [18] = STR [12];

CMP [Player] [19] = STR [13];

CMP [AOPLAYER] [0] = STR [12];

CMP [AOPLAYER] [1] = STR [13];

CMP [AOPLAYER] [12] = STR [8];

CMP [AOPLAYER] [13] = STR [9];

CMP [AOPLAYER] [16] = STR [10];

CMP [AOPLAYER] [17] = STR [11];

}

Void defconfig () / * config parts If you use the default settings, use this function. * /

{INT I;

For (i = 0; i <21; i )

{CMP [1] [i] = strDef [1] [i]; cmp [2] [i] = strdef [2] [i];

}

Void config (int player) / * config parts settings don't know what happened, right should not print * /

{CHAR CH1, CH2, STR [15], A [] = "about";

INT I, J, FLAG = 1;

CHAR PR [7] [11] = {{"/ N / 030"}, {"/ n / 033"}, {"/ n / 031"}, {"/ n / 032"}, {"/ nhui qi "}, {" / nren shu "}, {" / nque ding "}}

UNMAKE (STR, PLAYER);

Printf ("/ NPLAYER% D", Player;

For (i = 0; i <7; i )

{Printf (PR [I]);

CH1 = getChe (); if (! CH1) CH2 = getChe (); Else CH2 = 0;

IF (CH1 == 27) BREAK;

STR [I * 2] = CH1; STR [i * 2 1] = CH2;

IF (i == 4) / * Egg Setup Key When you knock ABOUT, you will see * / {

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

IF (STR [J * 2]! = A [J]) {FLAG = 0; Break;}

IF (flag) {defconfig ();

CLRSCR ();

Printf ("PROGAMMED BY GW / N");

GetChe (); BREAK;

}

}

}

Make (Str, Player);

}

Void RC () / * config parts reconfig () In addition to the arrow keys, others can not be repeated, otherwise this function is to be used * /

{Printf ("/ nsorry, you must reconfig / n");

CONFIG (1); config (2);

}

INT CHECK (INT * FLAG) / * Config part checks if no repeat key * /

{Char Str [3] [15];

INT I, J, K, L;

Unmake (STR [1], 1); unmake (STR [2], 2);

Printf ("/ nChecking ... / n");

For (k = 1, l = 2; k <3; k , l -)

For (i = 8; i <14; i = 2) for (j = 0; j <14; j = 2)

{IF (STR [K] [I] == STR [L] [J] && STR [K] [i 1] == STR [L] [J I])

{rc (); * flag = 0; return;}

IF (i == J) Continue;

IF (STR [K] [i] == STR [K] [J] && STR [K] [i 1] == STR [K] [J I])

{rc (); * flag = 0; return;}

}

Printf ("Pass / N");

}

Void isconfig () / * Config Component Config Main Function Main Interface * /

{Char CH;

INT flag = 1;

DEFCONFIG ();

IF (flag) {printf ("do you want to config? / npress y to config / n");

CH = getChe (); if (! CH) getche ();

IF (CH == 'y') {config (1); config (2); flag = 0;}

}

While (! flag)

{Printf ("/ ndo you want to reconfig? / npress y to reconfig / npress d to use default config / npress any other key to exit config / n");

CH = getChe (); if (! CH) getche ();

FLAG = 1;

IF (CH == 'D') {defconfig (); flag = 0;}

IF (CH == 'y') {config (1); config (2); flag = 0;}

Check (& ​​flag);

}

}

Void PGO (int * HQ, INT * RS) / * Player main interface * /

{INT I, J, X1, Y1, N;

CHAR CH1, CH2;

IF (! xn [p])

{XN [P] = Refresh1 (P); XN [P1] = Refresh1 (P1); P = P1; P1 = -P 3; Return;}

CLRSCR (); printhead (); gO (); refresh2 (); refresh3 ();

X1 = x [p] * 3; y1 = y [p] * 3; n = hmq (1) hmq (2); for (;;)

{

gotoxy (1, 1);

For (i = 0; i <25; i )

{Printf ("% s", qp [i]);

IF (i! = 24) Printf ("/ n");

}

gotoxy (x1 2, y1 3);

CH1 = getChe (); if (! CH1) CH2 = getChe ();

CH1 = TRANF (CH1, CH2);

Switch (CH1)

{CASE '1': Y1 = (Y1 21)% 24; GO (); Break;

Case '2': x1 = (x1 21)% 24; GO (); Break;

Case '3': Y1 = (Y1 3)% 24; GO (); Break;

Case '4': x1 = (x1 3)% 24; GO (); Break;

Case '5': IF (n <6) Break; * HQ = P; Return;

Case '6': IF (n <6) Break; * HQ = P1; Return;

Case '7': {CH2 = SURE ();

IF (CH2 == '9') {* rs = p; return;}

Else {Go (); Break;}

}

CASE '8': {CH2 = SURE ();

IF (CH2 == '0') {* RS = P1; Return;}

Else {Go (); Break;}

}

Case '9': {

IF (! lsqp [y1 / 3 1] [x1 / 3 1])

{gotoxy (26, 4); Clreol (); Printf ("IT's Impossible!"); Break;}

Play (x1, y1);

XN [P] = Refresh1 (P); XN [P1] = Refresh1 (P1);

P = P1; P1 = -P 3; return;

}

}

}

}

void main ()

{

CHAR CH;

INT HQ, TAG = 2, RS;

INT N;

ISCONFIG ();

For (;;)

{IF (M [2] || M [1])

{CLRSCR ();

Printf ("more again? / npress entry to payue / n");

CH = getChe (); if (ch-13) Break;}

P = -tag 3; p1 = -P 3; CLRSCR (); csqp (); rs = 0; HQ = 0;

XN [P1] = Refresh1 (P1); XN [P] = Refresh1 (P);

For (; (xn [2] || xn [1]) &&! rs;

{PGO (& HQ, & RS); if (HQ) HQ _ (& HQ);

N [1] = HMQ (1); N [0] = HMQ (2); CLRSCR ();

IF (RS == 2 || (RS == 0 && N [1]> N [0]))

{M [1] ; Printf ("Player1 Win! / N");

IF (rs == 1 || (rs == 0 && n [0]> n [1]))

{M [2] ; Printf ("Player2 Win! / N");

IF (RS == 0 && N [0] == N [1]) Printf ("DRAW! / N");

Printf ("Player1: Player2% D:% D / N", N [1], N [0]);

Printf ("Player1: Player2% D:% D / N", M [1], M [2]);

Printf ("Press Any Key To Continue / N);

CH = getChe (); if (! CH) getche ();

Tag = -TAG 3;

}

}

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

New Post(0)