How to use java to realize Horse pedal board game
Editor to share with you how to use java to achieve horse pedal board games, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The details are as follows
There is such a game in 4399 Mini Game.
This is the code implementation.
Package com.HorseChess;import java.awt.*;import java.util.ArrayList;import java.util.Comparator;import java.util.Scanner;public class HorseChess {private static int X; private static int Y; private static boolean visited []; private static boolean finished; public static void main (String [] args) {Scanner sc = new Scanner (System.in); System.out.println ("Please enter a line:"); X = sc.nextInt () System.out.println ("Please enter column:"); Y = sc.nextInt (); System.out.println ("Please enter the row of the chess piece:"); int row = sc.nextInt (); System.out.println ("enter the column of the chess piece:"); int column = sc.nextInt (); int [] [] chessboard = new int [X] [Y] Visited = new boolean [Xeroy]; traverchess (chessboard,row-1,column-1,1); for (int [] rows: chessboard) {for (int step: rows) {System.out.print (step + "\ t");} System.out.println () }} public static void traverchess (int [] [] chessboard,int row,int column,int step) {chessboard [row] [column] = step; visited [row * X+column] = true; ArrayList ps = next (new Point (column,row)); sort (ps); while (! ps.isEmpty ()) {Point p = ps.remove (0) If (! visited [p.y*X+p.x]) {traverchess (chessboard,p.y,p.x,step+1);}} if (step=0&& (p1.y = curpoint.y-1) > = 0) {ps.add (new Point (p1)) } if ((p1.x = curpoint.x-1) > = zero & (p1.y = curpoint.y-2) > = 0) {ps.add (new Point (p1));} if ((p1.x = curpoint.x + 1))
< X && (p1.y = curpoint.y - 2)>= 0) {ps.add (new Point (p1));} if ((p1.x = curpoint.x + 2)
< X && (p1.y = curpoint.y - 1)>= 0) {ps.add (new Point (p1));} if ((p1.x = curpoint.x + 2)