Java implements simple wuziqi

Source: Internet
Author: User
Import Java. io. *; import Java. io. bufferedreader; public class gobang {private string [] [] Board; Private Static int board_size = 15; Public void initboard () {board = new string [board_size] [board_size]; for (INT I = 0; I <board_size; I ++) {for (Int J = 0; j <board_size; j ++) {board [I] [J] = "+" ;}} public void printboard () {for (INT I = 0; I <board_size; I ++) {for (Int J = 0; j <board_size; j ++) {system. out. print (Board [I] [J]);} system. out. print ("\ n") ;}} public static void main (string [] ARGs) throws exception {gobang GB = new gobang (); GB. initboard (); GB. printboard (); bufferedreader BR = new bufferedreader (New inputstreamreader (system. in); string inputstr = NULL; while (inputstr = BR. readline ())! = NULL) {string [] posstrarr = inputstr. split (","); int xpos = integer. parseint (posstrarr [0]); int ypos = integer. parseint (posstrarr [1]); GB. board [yPos-1] [xPos-1] = "●";/* here should be the computer randomly generated two numbers, as the computer chess coordinates, to the Board array is different from the solid circle of the white pawns. Involved: 1. The validity of coordinates can only be numbers, not beyond the range of the board. 2. Point of the game, not repeated. 3. After each game, who needs to be scanned to win */GB. printboard ();/* and perform four rounds of scanning here to determine whether there are five chess moves in the horizontal, vertical, left oblique, and right oblique directions. */System. Out. println ("Enter the coordinates of your game. The coordinates should be in the format of X and Y :");}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.