Simple wuziqi on the console and wuziqi on the console
1 import java. util. break; 2 3 // console simple wuziqi 4 public class wuziqi {5 6 // two-dimensional array as board 7 private static char [] [] board = new char [16] [16]; 8 // 9 private static int cnt; 10 // representing the number of pawns in Player 11 private static char [] qizi = {'#','@'}; 12 // search for 13 private static int [] dx = {-,-1,-, 1 }; 14 private static int [] dy = {0,-1,-,-,}; 15 16 // input detection 17 private static int CheckInput (int x, int y) {18 19 if (board [x] [y]! = '+') 20 return 0; 21 if (x <1 | x> 15 | y <1 | y> 15) 22 return 0; 23 return 1; 24} 25 26 // boundary Check 27 private static int Check (int x, int y) {28 if (x> 15 | x <1 | y> 15 | y <1) 29 return 0; 30 return 1; 31} 32 // check whether the player wins. The player number and the current position coordinate 33 private static int CheckAns (int num, int x, int y) must be input) {34 if (cnt = 15*15) 35 return 1; 36 // determine whether five pieces are connected together in four directions: horizontal, vertical, left, and right. 37 for (int I = 0; I <4; I ++) {38 int sum = 1; 39 int xx = x + dx [I]; 40 I Nt yy = y + dy [I]; 41 while (board [xx] [yy] = qizi [num] & Check (xx, yy) = 1) {42 sum ++; 43 xx = xx + dx [I]; 44 yy = yy + dy [I]; 45} 46 xx = x + dx [7-i]; 47 yy = y + dy [7-i]; 48 while (board [xx] [yy] = qizi [num] & Check (xx, yy) = 1) {49 sum ++; 50 xx = xx + dx [7-i]; 51 yy = yy + dy [7-i]; 52} 53 if (sum> = 5) 54 return 1; 55} 56 return 0; 57} 58 59 // initialize 60 private static void Init () {61 cnt = 0; 62 for (int I = 1; I <= 15; I ++) 63 for (int j = 1; j <= 15; j ++) 64 board [I] [j] = '+'; 65} 66 67 // output board 68 private static void Print () {69 int I, j; 70 for (I = 1; I <= 15; I ++) {71 for (j = 1; j <= 15; j ++) {72 73 System. out. print (board [I] [j]); 74} 75 System. out. println (); 76} 77} 78 79 public static int run () {80 81 int x, y; 82 Init (); 83 // current player ID, 84 int num = 0; 85 while (true) {86 Print (); 87 System. out. print (num + 1 + "contestant, enter the coordinates of your chess player, in the form of x y:"); 88 then SC = n Ew values (System. in); 89 while (true) {90 x = SC. nextInt (); 91 y = SC. nextInt (); 92 if (CheckInput (x, y) = 1) 93 break; 94 System. out. print ("the input coordinates are invalid. Please enter them again:"); 95} 96 board [x] [y] = qizi [num]; 97 if (CheckAns (num, x, y) = 1) {98 return num + 1; 99} 100 num = 1-num; 101} 102} 103 104 public static void main (String [] args) {105 106 System. out. println ("welcome to the lkl Wuzi! "); 107 int ans = run (); 108 System. out. println (" congratulations "+ ans +" Winner "); 109} 110}