-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
package com.lvxinchun.game;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
public class AppRun {
public static final int TYPE_SIZE = 8;
public static final int ROW = 8;
public static final int COL = 8;
private static Random RAND = new Random();
private int[][] arr = new int[ROW][COL];
private static List<Integer> TYPE_SET = new ArrayList<Integer>();
public AppRun(){
for(int i = 0; i < 8; i++){
TYPE_SET.add(i);
}
}
public static void main(String[] args){
AppRun app = new AppRun();
app.initRand();
app.print();
System.out.print("Please input >>");
Scanner input=new Scanner(System.in); //定义一个从系统缓存读取数据的对偶
String str=input.next(); //从缓存中读出数据
String[] rcs = str.split("-");
int r1 = Integer.parseInt(rcs[0]);
int c1 = Integer.parseInt(rcs[1]);
int r2 = Integer.parseInt(rcs[2]);
int c2 = Integer.parseInt(rcs[3]);
System.out.println("(" + r1 + "," + c1 + ") <---> (" + r2 + "," + c2 + ")");//
app.exchange(r1, c1, r2, c2);
app.print();
if(app.checkSome().size() > 0){
System.out.println("==============");
}
}
public void initRand(){
for(int row = 0; row < ROW; row++){
for(int col = 0; col < COL; col++){
int left1 = -1,left2 = -1,up1 = -1,up2 = -1;
if(col >= 2){
left1 = arr[row][col-2];
left2 = arr[row][col-1];
}
if(row >= 2){
up1 = arr[row-2][col];
up2 = arr[row-1][col];
}
arr[row][col] = getNextType(left1, left2, up1, up2);
}
}
}
public void exchange(int r1, int c1, int r2, int c2){
int temp = arr[r1][c1];
arr[r1][c1] = arr[r2][c2];
arr[r2][c2] = temp;
}
public List<Arr> checkSome(){
List<Arr> list = new ArrayList<Arr>();
int i = 0;
int row = 0;
while(true){
if(arr[row][i] == arr[row][i+1]){
}
break;
}
return list;
//up
//down
//left
//right
}
public void print(){
for(int row = 0; row < ROW; row++){
for(int col = 0; col < COL; col++){
if(arr[row][col] == -1){
System.out.print("X-");
}else{
System.out.print(arr[row][col] + "-");
}
}
System.out.println();
}
System.out.println();
}
public int getNextType(int left1, int left2, int up1, int up2){
List<Integer> list = new ArrayList<Integer>();
if(left1 == left2){
if(up1 == up2){
for(int i = 0; i < TYPE_SIZE; i++){
if(i != left1 && i != up1){
list.add(i);
}
}
}else{
for(int i = 0; i < TYPE_SIZE; i++){
if(i != left1){
list.add(i);
}
}
}
}else{
if(up1 == up2){
for(int i = 0; i < TYPE_SIZE; i++){
if(i != up1){
list.add(i);
}
}
}else{
for(int i = 0; i < TYPE_SIZE; i++){
list.add(i);
}
}
}
int index = RAND.nextInt(list.size());
return list.get(index);
}
}
Metadata
Metadata
Assignees
Labels
No labels