Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Jewel1 #1

Copy link
Copy link

Description

@thinkingcoding
Issue body actions

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);
}

}

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.