こんにちは、これまでのところ、このコードを書きましたが、正常に動作しますが、 *とスペースのクリーンなセットが必要な場合、出力は私の期待を満たしていません。このあたり
import java.util.*;
class Cell4
{
public static void main (String[] args)
{
int l; //length of a row
int r; //stores the rule sequence
int g; //number of the generation
String a;//stands for automata
int p; //position of the true cells
int currentG; //current generation
Scanner scanner;
scanner= new Scanner(System.in);
a=scanner.next();
l=scanner.nextInt();
g=scanner.nextInt();
scanner.next();
boolean[][] cellsCurrent = new boolean[g][l+2];
currentG=0;
while(scanner.hasNextInt()){ //put the position values in an array
p=scanner.nextInt();
if(p<=l){
cellsCurrent[currentG][p] = true;
}
}
scanner.next();
if(a.equals("A")){
for(currentG=0; currentG<g-1; currentG++){ //for all generations
for(int i=1; i<l+1; i++){ //for all cells
if(cellsCurrent[currentG][i] == true && (cellsCurrent[currentG][i+1] == true ^ cellsCurrent[currentG][i-1] == true)){
cellsCurrent[currentG+1][i] = true;
}
else if (cellsCurrent[currentG][i] == true){
cellsCurrent[currentG+1][i] = false;
}
if(cellsCurrent[currentG][i] == false && cellsCurrent[currentG][i+1] == false && cellsCurrent[currentG][i-1] == false){
cellsCurrent[currentG+1][i] = false;
}
else if(cellsCurrent[currentG][i] == false){
cellsCurrent[currentG+1][i] = true;
}
}
}
}
if(a.equals("B")){
for(currentG=0; currentG<g-1; currentG++){ //for all generations
for(int i=1; i<l+1; i++){ //for all cells
if(cellsCurrent[currentG][i] == true && cellsCurrent[currentG][i+1] == false){
cellsCurrent[currentG+1][i] = true;
}
else if (cellsCurrent[currentG][i] == true){
cellsCurrent[currentG+1][i] = false;
}
if(cellsCurrent[currentG][i] == false && (cellsCurrent[currentG][i+1] == true ^ cellsCurrent[currentG][i-1] == true)){
cellsCurrent[currentG+1][i] = true;
}
else if (cellsCurrent[currentG][i] == false){
cellsCurrent[currentG+1][i] = false;
}
}
}
}
if (a.equals("U")){
boolean[] rules = new boolean[8];
for(int i=0;i<8;i++){ //put the position values in an array
r=scanner.nextInt();
if(r == 1){
rules[i] = true;
}
else if(r == 0){
rules[i] = false;
}
}
for(currentG=0; currentG<g-1; currentG++){ //for all generations
for(int i=1; i<l+1; i++){ //for all cells
if(cellsCurrent[currentG][i] == false && cellsCurrent[currentG][i+1] == false && cellsCurrent[currentG][i-1] == false){
cellsCurrent[currentG+1][i] = rules[0];
}
else if(cellsCurrent[currentG][i] == false && cellsCurrent[currentG][i-1] == false && cellsCurrent[currentG][i+1] == true){
cellsCurrent[currentG+1][i] = rules[1];
}
else if(cellsCurrent[currentG][i] == true && cellsCurrent[currentG][i-1] == false && cellsCurrent[currentG][i+1] == false){
cellsCurrent[currentG+1][i] = rules[2];
}
else if(cellsCurrent[currentG][i] == true && cellsCurrent[currentG][i-1] == false && cellsCurrent[currentG][i+1] == true){
cellsCurrent[currentG+1][i] = rules[3] ;
}
else if(cellsCurrent[currentG][i] == false && cellsCurrent[currentG][i-1] == true && cellsCurrent[currentG][i+1] == false){
cellsCurrent[currentG+1][i] = rules[4] ;
}
else if(cellsCurrent[currentG][i] == false && cellsCurrent[currentG][i-1] == true && cellsCurrent[currentG][i+1] == true){
cellsCurrent[currentG+1][i] = rules[5] ;
}
else if(cellsCurrent[currentG][i] == true && cellsCurrent[currentG][i-1] == true && cellsCurrent[currentG][i+1] == false){
cellsCurrent[currentG+1][i] = rules[6] ;
}
else if(cellsCurrent[currentG][i] == true && cellsCurrent[currentG][i-1] == true && cellsCurrent[currentG][i+1] == true){
cellsCurrent[currentG+1][i] = rules[7] ;
}
}
}
}
for (int i = 0; i < cellsCurrent.length; i++) {
System.out.println(Arrays.toString(cellsCurrent[i]).replace("true","*").replace("false"," "));
}
}
}