Bibi's DevLog ๐ค๐
[2021 ๋ง์คํฐ์ฆ ์ฝ์ค ํ ์คํธ] 3๋จ๊ณ : ๋ฃจ๋น ์ค ํ๋ธ ๊ตฌํํ๊ธฐ ๋ณธ๋ฌธ
[2021 ๋ง์คํฐ์ฆ ์ฝ์ค ํ ์คํธ] 3๋จ๊ณ : ๋ฃจ๋น ์ค ํ๋ธ ๊ตฌํํ๊ธฐ
๋น๋น bibi 2020. 12. 14. 17:362021 ์ฝ๋์ค์ฟผ๋ ๋ง์คํฐ์ฆ ์ฝ์ค ํ ์คํธ ๋ฌธ์ ์ ์ ์ ํ์ด๋ฅผ ๊ณต์ ํ๋ ๊ธ์ ๋๋ค.
3๋จ๊ณ: ๋ฃจ๋น ์ค ํ๋ธ ๊ตฌํํ๊ธฐ
- ์ฐธ๊ณ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํด์ ๋ฃจ๋น ์ค ํ๋ธ๋ฅผ ๊ตฌํํ๋ค.
- ํ๋ธ๋ W, B, G, Y, O, R์ 6๊ฐ์ง ์๊น์ ๊ฐ์ง๊ณ ์๋ค.
- ์ ๋ ฅ: ๊ฐ ์กฐ์๋ฒ์ ํ ์ค๋ก ์ ๋ ฅ๋ฐ๋๋ค.
- ์ถ๋ ฅ: ํ๋ธ์ 6๋ฉด์ ํผ์น ์ํ๋ก ์ถ๋ ฅํ๋ค.
- Q๋ฅผ ์ ๋ ฅ๋ฐ์ผ๋ฉด ํ๋ก๊ทธ๋จ์ ์ข ๋ฃํ๊ณ , ์กฐ์ ๋ฐ์ ๋ช ๋ น์ ๊ฐฏ์๋ฅผ ์ถ๋ ฅ์ํจ๋ค.
ํ๋ธ์ ์ด๊ธฐ ์ํ
B B B
B B B
B B B
W W W O O O G G G Y Y Y
W W W O O O G G G Y Y Y
W W W O O O G G G Y Y Y
R R R
R R R
R R R
ํ๋ก๊ทธ๋จ ์์
(์ด๊ธฐ ์ํ ์ถ๋ ฅ)
CUBE> FRR'U2R
F
(ํ๋ธ์ํ)
R
(ํ๋ธ์ํ)
...
R
(ํ๋ธ์ํ)
CUBE> Q
๊ฒฝ๊ณผ์๊ฐ: 00:31 //์ถ๊ฐ ๊ตฌํ ํญ๋ชฉ
์กฐ์๊ฐฏ์: 6
์ด์ฉํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. ๋๋๋.
์ถ๊ฐ ๊ตฌํ ๊ธฐ๋ฅ
- ํ๋ก๊ทธ๋จ ์ข ๋ฃ ์ ๊ฒฝ๊ณผ ์๊ฐ ์ถ๋ ฅ
- ํ๋ธ์ ๋ฌด์์ ์๊ธฐ ๊ธฐ๋ฅ
- ๋ชจ๋ ๋ฉด์ ๋ง์ถ๋ฉด ์ถํ ๋ฉ์์ง์ ํจ๊ป ํ๋ก๊ทธ๋จ์ ์๋ ์ข ๋ฃ
3๋จ๊ณ ์ฝ๋ฉ ์๊ตฌ์ฌํญ
- ๊ฐ๋ฅํ ํ ์ปค๋ฐ์ ์์ฃผ ํ๊ณ ๊ตฌํ์ ์๋ฏธ๊ฐ ๋ช ํํ๊ฒ ์ ๋ฌ๋๋๋ก ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ์์ฑํ ๊ฒ
- ํจ์๋ ๋ฉ์๋๋ ํ ๋ฒ์ ํ ๊ฐ์ง ์ผ์ ํ๊ณ ๊ฐ๋ฅํ๋ฉด 20์ค์ด ๋์ง ์๋๋ก ๊ตฌํํ๋ค.
- ํจ์๋ ๋ฉ์๋์ ๋ค์ฌ์ฐ๊ธฐ๋ฅผ ๊ฐ๋ฅํ๋ฉด ์ ๊ฒ(3๋จ๊ณ๊น์ง๋ง) ํ ์ ์๋๋ก ๋ ธ๋ ฅํด ๋ณธ๋ค.
function main() {
for() {// ๋ค์ฌ์ฐ๊ธฐ 1๋จ๊ณ
if() { // ๋ค์ฌ์ฐ๊ธฐ 2๋จ๊ณ
return; // ๋ค์ฌ์ฐ๊ธฐ 3๋จ๊ณ
}
}
}
์์ค์ฝ๋
์๋๋ ์ ๊ฐ ์ ์ถํ ํ์ผ์ ๋๋ค.
package Step3;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Random;
import java.util.Objects;
public class Step3 { // ๋ฃจ๋น
์ค ํ๋ธ ๊ตฌํํ๊ธฐ
Scanner sc = new Scanner(System.in);
char[][] cubeUp = new char[3][3]; // ์๋ฉด
char[][] cubeLeft = new char[3][3]; // ์ผ์ชฝ๋ฉด
char[][] cubeFront = new char[3][3]; // ์๋ฉด
char[][] cubeRight = new char[3][3]; // ์ค๋ฅธ์ชฝ๋ฉด
char[][] cubeBack = new char[3][3]; // ๋ท๋ฉด
char[][] cubeDown = new char[3][3]; // ์๋ซ๋ฉด
int countNum = 0; // ์กฐ์ ํ์
long countTime = 0; // ๊ฒฝ๊ณผ์๊ฐ
public static void main(String[] args) {
Step3 step3 = new Step3();
System.out.println("๐ ๋ฃจ๋น
์ค ํ๋ธ๋ฅผ ํ์ด ๋ณด์ธ์!");
step3.initCube();
step3.scramble(); // ์ฒ์๋ถํฐ ์์ด์ ๋ณด์ฌ์ฃผ๊ธฐ
step3.ready();
}
public void initCube() {
for (int i = 0; i < 3; i++) {
cubeUp[i] = new char[]{'W', 'W', 'W'}; // ์๋ฉด ๊ธฐ๋ณธ ์ : White
cubeLeft[i] = new char[]{'O', 'O', 'O'}; // ์ผ์ชฝ๋ฉด ๊ธฐ๋ณธ ์ : Orange
cubeFront[i] = new char[]{'G', 'G', 'G'}; // ์๋ฉด ๊ธฐ๋ณธ ์ : Green
cubeRight[i] = new char[]{'R', 'R', 'R'}; // ์ค๋ฅธ์ชฝ๋ฉด ๊ธฐ๋ณธ ์ : Red
cubeBack[i] = new char[]{'B', 'B', 'B'}; // ๋ท๋ฉด ๊ธฐ๋ณธ ์ : Blue
cubeDown[i] = new char[]{'Y', 'Y', 'Y'}; // ์๋ซ๋ฉด ๊ธฐ๋ณธ ์ : Yellow
}
printCube();
}
public void scramble() { // ์๊ธฐ ๋ฉ์๋
char[][] tempUp = new char[3][3];
char[][] tempLeft = new char[3][3];
char[][] tempFront = new char[3][3];
char[][] tempRight = new char[3][3];
char[][] tempBack = new char[3][3];
char[][] tempDown = new char[3][3];
Random random = new Random();
int randomNum1 = random.nextInt(4); // 0~3๊น์ง ๋๋คํ๊ฒ ํธ์ถ. bound5์ด์์ด ๋๋ฉด 360๋๋ฅผ ๋์์ ์ ์์ผ๋๊ฐ ๋ง์ ์กฐ์ ํจ.
int randomNum2 = random.nextInt(4);
int randomNum3 = random.nextInt(4);
for (int i = 0; i < randomNum1; i++) {
whenU(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenDDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
}
for (int i = 0; i < randomNum2; i++) {
whenF(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenB(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
}
for (int i = 0; i < randomNum3; i++) {
whenL(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenD(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
}
for (int i = 0; i < randomNum1; i++) {
whenR(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenFDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
}
System.out.println("\n\n ๐ ๐ ํ๋ธ๋ฅผ ๋ฌด์์๋ก ์์์ต๋๋ค.");
printCube();
countTime = System.currentTimeMillis();
}
public void ready() {
String input = start();
ArrayList<String> inputList = trimInput(input);
checkInput(inputList);
}
public void printCube() {
for (int i = 0; i < 3; i++) {
System.out.printf("%n %6c %1c %1c %1c %6c", ' ', cubeUp[i][0], cubeUp[i][1], cubeUp[i][2], ' ');
}
for (int i = 0; i < 3; i++) {
System.out.printf("%n %1c %1c %1c %1c %1c %1c %1c %1c %1c %1c %1c %1c",
cubeLeft[i][0], cubeLeft[i][1], cubeLeft[i][2],
cubeFront[i][0], cubeFront[i][1], cubeFront[i][2],
cubeRight[i][0], cubeRight[i][1], cubeRight[i][2],
cubeBack[i][0], cubeBack[i][1], cubeBack[i][2]);
}
System.out.printf("%n %6c %1c %1c %1c %15c %1c%1c", ' ', cubeDown[0][0], cubeDown[0][1], cubeDown[0][2], ' ', ' ', 'U');
System.out.printf("%n %6c %1c %1c %1c %15c %1c%1c%1c%1c", ' ', cubeDown[1][0], cubeDown[1][1], cubeDown[1][2], ' ', 'L', 'F', 'R', 'B');
System.out.printf("%n %6c %1c %1c %1c %15c %1c%1c", ' ', cubeDown[2][0], cubeDown[2][1], cubeDown[2][2], ' ', ' ', 'D');
}
public String start() {
System.out.println("\nโ ------------------------- โ ใ์ ๊ฐ๋ ๋์๋งใ ------------------------------");
System.out.println(">> U = Up = ์๋ฉด, L = Left = ์ผ์ชฝ ๋ฉด, F = Front = ์๋ฉด, ");
System.out.println(">> R = Right = ์ค๋ฅธ์ชฝ ๋ฉด, B = Back = ๋ท๋ฉด, D = Down = ์๋ซ๋ฉด์ ๋ปํฉ๋๋ค.");
System.out.println("--------------------------------------------------------------------------");
System.out.println("โคต ์๋ ๋ช
๋ น์ด์ ๋ฐ๋ผ '์๊ณ๋ฐฉํฅ'์ผ๋ก '1/4๋ฐํด' ๋์๊ฐ๋๋ค.");
System.out.println(" U : ์๋ฉด, L : ์ผ์ชฝ ๋ฉด, F : ์๋ฉด, R : ์ค๋ฅธ์ชฝ ๋ฉด, B : ๋ท๋ฉด, D : ์๋ซ๋ฉด");
System.out.println("โคด ์๋ ๋ช
๋ น์ด์ ๋ฐ๋ผ '๋ฐ์๊ณ๋ฐฉํฅ'์ผ๋ก '1/4๋ฐํด' ๋์๊ฐ๋๋ค.");
System.out.println(" U' : ์๋ฉด, L' : ์ผ์ชฝ ๋ฉด, F' : ์๋ฉด, R' : ์ค๋ฅธ์ชฝ ๋ฉด, B' : ๋ท๋ฉด, D' : ์๋ซ๋ฉด");
System.out.println("๐ ์๋ ๋ช
๋ น์ด์ ๋ฐ๋ผ '์๊ณ๋ฐฉํฅ'์ผ๋ก '1/2๋ฐํด' ๋์๊ฐ๋๋ค.");
System.out.println(" U2 : ์๋ฉด, L2 : ์ผ์ชฝ ๋ฉด, F2 : ์๋ฉด, R2 : ์ค๋ฅธ์ชฝ ๋ฉด, B2 : ๋ท๋ฉด, D2 : ์๋ซ๋ฉด");
System.out.println("โ Q ๋ฅผ ์
๋ ฅํ๋ฉด ํ๋ก๊ทธ๋จ์ด ์ข
๋ฃ๋ฉ๋๋ค.");
System.out.print("CUBE > ");
String input = sc.nextLine();
System.out.println(); // ๊ฐํ
return input;
}
public ArrayList<String> trimInput(String input) { // ์
๋ ฅ๊ฐ ๋ค๋ฌ๊ธฐ
String[] inputArr = input.split("");
int inputArrLength = inputArr.length;
ArrayList<String> inputList = new ArrayList<>();
for (int i = 0; i < inputArrLength; i++) { // ์์๊ฐ '๋ 2์ด๋ฉด ์ง์ ์์์ '๋ 2๋ฅผ ๋ถ์ด๊ธฐ
String inputElement = inputArr[i];
if (inputElement.equals("'")) {
inputArr[i - 1] = inputArr[i - 1] + "'";
}
if (inputElement.equals("2")) {
inputArr[i - 1] = inputArr[i - 1] + "2";
}
}
for (int i = 0; i < inputArrLength; i++) { // ์์๊ฐ '์ด ์๋๊ณ 2๊ฐ ์๋ ๋ inputList์ ์ถ๊ฐ
String inputElement = inputArr[i];
if (!inputElement.equals("'") && !inputElement.equals("2")) {
inputList.add(inputElement);
}
}
return inputList;
}
public void checkInput(ArrayList<String> inputList) {
int inputListSize = inputList.size();
for (int i = 0; i < inputListSize; i++) {
String anInput = inputList.get(i);
if (anInput.equals("U'") || anInput.equals("U") || anInput.equals("F'") || anInput.equals("F")
|| anInput.equals("L'") || anInput.equals("L") || anInput.equals("R'") || anInput.equals("R")
|| anInput.equals("B'") || anInput.equals("B") || anInput.equals("D'") || anInput.equals("D")
|| anInput.equals("U2") || anInput.equals("L2") || anInput.equals("F2") || anInput.equals("R2")
|| anInput.equals("B2") || anInput.equals("D2") || anInput.equals("Q")) {
guideInput(anInput);
} else {
System.out.println("โ ์ง์ ๋์ง ์์ ๋ช
๋ น์ด๊ฐ ํฌํจ๋์ด ์์ต๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.");
String reInput = start();
ArrayList<String> reInputList = trimInput(reInput);
checkInput(reInputList);
}
}
isComplete();
ready();
}
public void isComplete() {
char[][] completeUp = new char[3][3];
char[][] completeLeft = new char[3][3];
char[][] completeFront = new char[3][3];
char[][] completeRight = new char[3][3];
char[][] completeBack = new char[3][3];
char[][] completeDown = new char[3][3];
for (int i = 0; i < 3; i++) {
completeUp[i] = new char[]{'W', 'W', 'W'}; // completeUp : White
completeLeft[i] = new char[]{'O', 'O', 'O'}; // completeLeft : Orange
completeFront[i] = new char[]{'G', 'G', 'G'}; // completeFront : Green
completeRight[i] = new char[]{'R', 'R', 'R'}; // completeRight : Red
completeBack[i] = new char[]{'B', 'B', 'B'}; // completeBack : Blue
completeDown[i] = new char[]{'Y', 'Y', 'Y'}; // completeDown : Yellow
}
if (Objects.deepEquals(cubeUp, completeUp) && Objects.deepEquals(cubeLeft, completeLeft)
&& Objects.deepEquals(cubeFront, completeFront) && Objects.deepEquals(cubeRight, completeRight)
&& Objects.deepEquals(cubeBack, completeBack) && Objects.deepEquals(cubeDown, completeDown)) {
System.out.println("๐๐๐ ์ถํ๋๋ฆฝ๋๋ค! ํ๋ธ๋ฅผ ์์ฑํ์ต๋๋ค! ๐๐๐");
terminate();
}
}
public void terminate() { // ์ข
๋ฃ ๋ฉ์๋
sc.close();
long timeGap = calTime();
long timeGapMinute = (timeGap) / (1000 * 60); // ๋ฐ๋ฆฌ์ด๋ฅผ ๋ถ ๋จ์๋ก ๋๋๊ธฐ
long timeGapSecond = (timeGap - (timeGapMinute * 1000 * 60)) / 1000; // ๋ถ์ ๋ค์ ๋ฐ๋ฆฌ์ด๋จ์๋ก ๋ฐ๊ฟ์ ๋ฐ๋ฆฌ์ด-๋ถ์ ์ด ๋จ์๋ก ๋๋๊ธฐ
System.out.println("\n๐ ๊ฒฝ๊ณผ์๊ฐ : " + timeGapMinute + "๋ถ " + timeGapSecond + "์ด");
System.out.println("๐ ์กฐ์ ํ์ : " + countNum + "ํ");
System.out.println("\n๐ ์ด์ฉํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.");
System.exit(0);
}
public long calTime() {
long startTime = countTime;
long endTime = System.currentTimeMillis();
long timeGap = endTime - startTime;
return timeGap;
}
public void guideInput(String anInput) {
char[][] tempUp = new char[3][3];
char[][] tempLeft = new char[3][3];
char[][] tempFront = new char[3][3];
char[][] tempRight = new char[3][3];
char[][] tempBack = new char[3][3];
char[][] tempDown = new char[3][3];
switch (anInput) {
case "U":
System.out.println("\nU : ์๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenU(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "U2":
System.out.println("\nU2 : ์๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/2 ํ์ ");
whenU(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenU(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "U'":
System.out.println("\nU' : ์์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenUDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "F":
System.out.println("\nF : ์๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenF(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "F2":
System.out.println("\nF2 : ์๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/2 ํ์ ");
whenF(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenF(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "F'":
System.out.println("\nF' : ์์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenFDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "L":
System.out.println("\nL : ์ผ์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenL(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "L2":
System.out.println("\nL2 : ์ผ์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/2 ํ์ ");
whenL(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenL(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "L'":
System.out.println("\nL' : ์ผ์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenLDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "R":
System.out.println("\nR : ์ค๋ฅธ์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenR(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "R2":
System.out.println("\nR2 : ์ค๋ฅธ์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/2 ํ์ ");
whenR(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenR(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "R'":
System.out.println("\nR' : ์ค๋ฅธ์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenRDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "B":
System.out.println("\nB : ๋ท๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenB(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "B2":
System.out.println("\nB2 : ๋ท๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/2 ํ์ ");
whenB(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenB(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "B'":
System.out.println("\nB' : ๋ท๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenBDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "D":
System.out.println("\nD : ์๋ซ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenD(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "D2":
System.out.println("\nD2 : ์๋ซ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/2 ํ์ ");
whenD(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
whenD(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "D'":
System.out.println("\nD' : ์๋ซ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ");
whenDDot(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);
break;
case "Q":
System.out.println("โ ํ๋ก๊ทธ๋จ ์ข
๋ฃ");
terminate();
break;
}
countNum++;
printCube();
System.out.println(); // ์ค๋ฐ๊ฟ
}
public void copyToTemp(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
for (int i = 0; i < 3; i++) { // ์์๋ณ์์ cube๋ด์ฉ ๋ณต์ฌ
for (int j = 0; j < 3; j++) {
tempUp[i][j] = cubeUp[i][j];
tempLeft[i][j] = cubeLeft[i][j];
tempFront[i][j] = cubeFront[i][j];
tempRight[i][j] = cubeRight[i][j];
tempBack[i][j] = cubeBack[i][j];
tempDown[i][j] = cubeDown[i][j];
}
}
}
public void copyToCube(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) { //ํ๋ผ๋ฏธํฐ5๊ฐ
for (int i = 0; i < 3; i++) { // cube์ ์์๋ณ์ ๋ด์ฉ ๋ณต์ฌ
for (int j = 0; j < 3; j++) {
cubeUp[i][j] = tempUp[i][j];
cubeLeft[i][j] = tempLeft[i][j];
cubeFront[i][j] = tempFront[i][j];
cubeRight[i][j] = tempRight[i][j];
cubeBack[i][j] = tempBack[i][j];
cubeDown[i][j] = tempDown[i][j];
}
}
}
public void clockWise(char[][] temp, char[][] cube) { // ํด๋น ๋ฉด cube๋ฅผ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ํด temp์ ๋์
.
temp[0][0] = cube[2][0];
temp[0][1] = cube[1][0];
temp[0][2] = cube[0][0];
temp[1][0] = cube[2][1];
temp[1][2] = cube[0][1];
temp[2][0] = cube[2][2];
temp[2][1] = cube[1][2];
temp[2][2] = cube[0][2];
}
public void counterClockWise(char[][] temp, char[][] cube) { // ํด๋น ๋ฉด cube๋ฅผ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ํด temp์ ๋์
.
temp[0][0] = cube[0][2];
temp[0][1] = cube[1][2];
temp[0][2] = cube[2][2];
temp[1][0] = cube[0][1];
temp[1][2] = cube[2][1];
temp[2][0] = cube[0][0];
temp[2][1] = cube[1][0];
temp[2][2] = cube[2][0];
}
public void whenU(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// U : ์์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
clockWise(tempUp, cubeUp);// U๋ฉด ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempLeft[0][0] = cubeFront[0][0]; // U๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[0][1] = cubeFront[0][1];
tempLeft[0][2] = cubeFront[0][2];
tempBack[0][0] = cubeLeft[0][0];// U๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[0][1] = cubeLeft[0][1];
tempBack[0][2] = cubeLeft[0][2];
tempFront[0][0] = cubeRight[0][0];// U๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[0][1] = cubeRight[0][1];
tempFront[0][2] = cubeRight[0][2];
tempRight[0][0] = cubeBack[0][0];// U๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[0][1] = cubeBack[0][1];
tempRight[0][2] = cubeBack[0][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);//๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenUDot(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// U' : ์์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
counterClockWise(tempUp, cubeUp);// U๋ฉด ๋ฐ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempLeft[0][0] = cubeBack[0][0]; // U๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[0][1] = cubeBack[0][1];
tempLeft[0][2] = cubeBack[0][2];
tempFront[0][0] = cubeLeft[0][0];// U๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[0][1] = cubeLeft[0][1];
tempFront[0][2] = cubeLeft[0][2];
tempRight[0][0] = cubeFront[0][0];// U๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[0][1] = cubeFront[0][1];
tempRight[0][2] = cubeFront[0][2];
tempBack[0][0] = cubeRight[0][0];// U๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[0][1] = cubeRight[0][1];
tempBack[0][2] = cubeRight[0][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown); //๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenL(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// L : ์ผ์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
clockWise(tempLeft, cubeLeft);// L๋ฉด ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[0][0] = cubeBack[2][2];// L๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[1][0] = cubeBack[1][2];
tempUp[2][0] = cubeBack[0][2];
tempFront[0][0] = cubeUp[0][0];// L๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[1][0] = cubeUp[1][0];
tempFront[2][0] = cubeUp[2][0];
tempDown[0][0] = cubeFront[0][0];// L๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[1][0] = cubeFront[1][0];
tempDown[2][0] = cubeFront[2][0];
tempBack[0][2] = cubeDown[2][0]; // L๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[1][2] = cubeDown[1][0];
tempBack[2][2] = cubeDown[0][0];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenLDot(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// L' : ์ผ์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
counterClockWise(tempLeft, cubeLeft);// L๋ฉด ๋ฐ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[0][0] = cubeFront[0][0];// L๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[1][0] = cubeFront[1][0];
tempUp[2][0] = cubeFront[2][0];
tempFront[0][0] = cubeDown[0][0]; // L๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[1][0] = cubeDown[1][0];
tempFront[2][0] = cubeDown[2][0];
tempDown[0][0] = cubeBack[2][2];// L๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[1][0] = cubeBack[1][2];
tempDown[2][0] = cubeBack[0][2];
tempBack[0][2] = cubeUp[2][0];// L๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[1][2] = cubeUp[1][0];
tempBack[2][2] = cubeUp[0][0];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenF(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// F : ์์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
clockWise(tempFront, cubeFront);// F๋ฉด ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[2][0] = cubeLeft[2][2];// F๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[2][1] = cubeLeft[1][2];
tempUp[2][2] = cubeLeft[0][2];
tempLeft[0][2] = cubeDown[0][0]; // F๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[1][2] = cubeDown[0][1];
tempLeft[2][2] = cubeDown[0][2];
tempRight[0][0] = cubeUp[2][0];// F๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[1][0] = cubeUp[2][1];
tempRight[2][0] = cubeUp[2][2];
tempDown[0][0] = cubeRight[2][0];// F๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[0][1] = cubeRight[1][0];
tempDown[0][2] = cubeRight[0][0];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown); // ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenFDot(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// F' : ์์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown); // ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
counterClockWise(tempFront, cubeFront);// F๋ฉด ๋ฐ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[2][0] = cubeRight[0][0];// F๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[2][1] = cubeRight[1][0];
tempUp[2][2] = cubeRight[2][0];
tempLeft[0][2] = cubeUp[2][2]; // F๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[1][2] = cubeUp[2][1];
tempLeft[2][2] = cubeUp[2][0];
tempRight[0][0] = cubeDown[0][2];// F๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[1][0] = cubeDown[0][1];
tempRight[2][0] = cubeDown[0][0];
tempDown[0][0] = cubeLeft[0][2];// F๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[0][1] = cubeLeft[1][2];
tempDown[0][2] = cubeLeft[2][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenR(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// R : ์ค๋ฅธ์ชฝ ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
clockWise(tempRight, cubeRight);// R๋ฉด ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[0][2] = cubeFront[0][2];// R๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[1][2] = cubeFront[1][2];
tempUp[2][2] = cubeFront[2][2];
tempFront[0][2] = cubeDown[0][2];// R๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[1][2] = cubeDown[1][2];
tempFront[2][2] = cubeDown[2][2];
tempDown[0][2] = cubeBack[2][0];// R๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[1][2] = cubeBack[1][0];
tempDown[2][2] = cubeBack[0][0];
tempBack[0][0] = cubeUp[2][2]; // R๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[1][0] = cubeUp[1][2];
tempBack[2][0] = cubeUp[0][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenRDot(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// R' : ์ค๋ฅธ์ชฝ ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
counterClockWise(tempRight, cubeRight);// R๋ฉด ๋ฐ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[0][2] = cubeBack[2][0];// R๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[1][2] = cubeBack[1][0];
tempUp[2][2] = cubeBack[0][0];
tempFront[0][2] = cubeUp[0][2]; // R๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[1][2] = cubeUp[1][2];
tempFront[2][2] = cubeUp[2][2];
tempDown[0][2] = cubeFront[0][2];// R๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[1][2] = cubeFront[1][2];
tempDown[2][2] = cubeFront[2][2];
tempBack[0][0] = cubeDown[2][2];// R๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[1][0] = cubeDown[1][2];
tempBack[2][0] = cubeDown[0][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenB(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// B : ๋ท๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
clockWise(tempBack, cubeBack);// B๋ฉด ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[0][0] = cubeRight[0][2];// B๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[0][1] = cubeRight[1][2];
tempUp[0][2] = cubeRight[2][2];
tempLeft[0][0] = cubeUp[0][2];// B๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[1][0] = cubeUp[0][1];
tempLeft[2][0] = cubeUp[0][0];
tempRight[0][2] = cubeDown[2][2]; // B๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[1][2] = cubeDown[2][1];
tempRight[2][2] = cubeDown[2][0];
tempDown[2][0] = cubeLeft[0][0];// B๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[2][1] = cubeLeft[1][0];
tempDown[2][2] = cubeLeft[2][0];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenBDot(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// B' : ๋ท๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
counterClockWise(tempBack, cubeBack);// B๋ฉด ๋ฐ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempUp[0][0] = cubeLeft[2][0];// B๋ฉด์ ์๋ฉด - U๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempUp[0][1] = cubeLeft[1][0];
tempUp[0][2] = cubeLeft[0][0];
tempLeft[0][0] = cubeDown[2][0]; // B๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[1][0] = cubeDown[2][1];
tempLeft[2][0] = cubeDown[2][2];
tempRight[0][2] = cubeUp[0][0];// B๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[1][2] = cubeUp[0][1];
tempRight[2][2] = cubeUp[0][2];
tempDown[2][0] = cubeRight[2][2];// B๋ฉด์ ์๋ฉด - D๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempDown[2][1] = cubeRight[1][2];
tempDown[2][2] = cubeRight[0][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenD(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// D : ์๋ซ๋ฉด์ ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
clockWise(tempDown, cubeDown);// D๋ฉด ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempLeft[2][0] = cubeBack[2][0];// D๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[2][1] = cubeBack[2][1];
tempLeft[2][2] = cubeBack[2][2];
tempFront[2][0] = cubeLeft[2][0];// D๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[2][1] = cubeLeft[2][1];
tempFront[2][2] = cubeLeft[2][2];
tempRight[2][0] = cubeFront[2][0]; // D๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[2][1] = cubeFront[2][1];
tempRight[2][2] = cubeFront[2][2];
tempBack[2][0] = cubeRight[2][0];// D๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[2][1] = cubeRight[2][1];
tempBack[2][2] = cubeRight[2][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
public void whenDDot(char[][] tempUp, char[][] tempLeft, char[][] tempFront, char[][] tempRight, char[][] tempBack, char[][] tempDown) {
// D' : ์๋ซ๋ฉด์ ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์
copyToTemp(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ์์๋ณ์์ cube ๋ด์ฉ ๋ณต์ฌ
counterClockWise(tempDown, cubeDown);// D๋ฉด ๋ฐ์๊ณ๋ฐฉํฅ 1/4 ํ์
tempLeft[2][0] = cubeFront[2][0]; // D๋ฉด์ ์๋ฉด - L๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempLeft[2][1] = cubeFront[2][1];
tempLeft[2][2] = cubeFront[2][2];
tempFront[2][0] = cubeRight[2][0];// D๋ฉด์ ์๋ฉด - F๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempFront[2][1] = cubeRight[2][1];
tempFront[2][2] = cubeRight[2][2];
tempRight[2][0] = cubeBack[2][0];// D๋ฉด์ ์๋ฉด - R๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempRight[2][1] = cubeBack[2][1];
tempRight[2][2] = cubeBack[2][2];
tempBack[2][0] = cubeLeft[2][0];// D๋ฉด์ ์๋ฉด - B๋ฉด ๋ณ๊ฒฝ์ฌํญ
tempBack[2][1] = cubeLeft[2][1];
tempBack[2][2] = cubeLeft[2][2];
copyToCube(tempUp, tempLeft, tempFront, tempRight, tempBack, tempDown);// ๋ฐ๋ ์์๋ณ์๋ฅผ cube์ ๋ณต์ฌ
}
} // class
์ถ๋ ฅํํ
์ค๋ช
Step3.java ์ฝ๋ ์ค๋ช
-
์ ์ญ๋ณ์
- sc : Scanner
- cubeUp, cubeLeft, cubeFront, cubeRight, cubeBack, cubeDown
- ํ๋ธ์ 6๋ฉด(์์ชฝ, ์ผ์ชฝ, ์์ชฝ, ์ค๋ฅธ์ชฝ, ๋ท์ชฝ, ์๋ซ์ชฝ)์ ๋ด๋นํ๋ 3*3 ์ด์ฐจ์๋ฐฐ์ด
- countNum : ์กฐ์ ํ์๋ฅผ ์นด์ดํ ํ๋ ๋ณ์
- countTime : ๊ฒฝ๊ณผ์๊ฐ์ ์ธก์ ํ๋ ๋ณ์
-
initCube() : ํ๋ธ๋ฅผ ์ด๊ธฐํํ๋ ๋ฉ์๋.
- ํ๋ธ์ 6๋ฉด์ ๊ธฐ๋ณธ ์์ผ๋ก ์ค์
- ์๋ฉด = White, ์ผ์ชฝ๋ฉด = Orange, ์๋ฉด = Green
- ์ค๋ฅธ์ชฝ๋ฉด = Red, ๋ท๋ฉด = Blue, ์๋ซ๋ฉด = Yellow
-
scramble() : ํ๋ธ๋ฅผ ๋ฌด์์๋ก ์๋ ๋ฉ์๋.
- ๋ฃจ๋น ์ค ํ๋ธ๋ฅผ ํธ๋ ํ๋ก๊ทธ๋จ์ด๊ธฐ ๋๋ฌธ์ ์ฒซ ํ๋ฉด์ ์ ์ํ ๋ค ์๋์ผ๋ก ์์ด์ค๋ค.
- random.nextInt(4)๋ฅผ ํตํด 0~3๊น์ง์ ๋ฌด์์ ์ซ์๋ฅผ 3๊ฐ ํธ์ถ
- ์ผ๋ถ ํ๋ธํ์ ๋ฉ์๋๋ค์ ํตํด ๋ฌด์์ ์ซ์๋งํผ ํ๋ธ๋ฅผ ์์ ๋ค ๊ทธ ๋ชจ์ต์ ์ถ๋ ฅํ๋ค.
- ์์ธ ํ๋ธ๊ฐ ์ถ๋ ฅ๋ ์์ ๋ถํฐ ์๊ฐ์ด ๊ณ์ฐ๋๋ค(countTime).
-
ready() : start()-trimInput()-checkInput()์ ์ฐจ๋ก๋ก ํธ์ถํ๋ ๋ฉ์๋.
- ๊ฐ๊ฐ ์ ํจ์์ ๋ฆฌํด๊ฐ์ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ๋๋ค.
-
printCube() : ํ์ฌ ํ๋ธ 6๋ฉด์ ์ํ๋ฅผ ์ ๊ฐ๋ ๋ชจ์์ผ๋ก ์ถ๋ ฅํ๊ณ , ์ ๊ฐ๋ ๋์๋ง์ ์ ๊ณตํ๋ ๋ฉ์๋.
- printf()๋ฅผ ํ์ฉํด ํ๋ธ์ 6๋ฉด์ ์ ๊ฐ๋ ๋ชจ์์ผ๋ก ์ถ๋ ฅ
- ํ์ฌ ํ๋ธ์ ๋ชจ์ ์ค๋ฅธ์ชฝ์, ์ ๊ฐ๋์ ๊ฐ ๋ฉด์ ๋ํ ๋ช
๋ น์ด ๊ธฐํธ๋ฅผ ์ ๊ณต
- ์ค์ ๋ก ์ฌ์ฉ์์๊ฒ๋ ๊ฐ ๋ฉด์ ๋ํ ์ค๋ช ์ด ํ์ํ ๊ฒ ๊ฐ์ ์ถ๊ฐํจ.
-
start() : ๋์๋ง ๋ฐ ๋ช ๋ น์ด ์ค๋ช ์ ์ ๊ณตํ๊ณ , ์ฌ์ฉ์์๊ฒ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅ๋ฐ๋ ๋ฉ์๋.
- return : input (์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ๋ฐ์ ๋ช ๋ น์ด)
-
trimInput(input) : ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ๋ฐ์ ๋ช ๋ น์ด๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ข์ ํํ๋ก ๋ค๋ฌ๋ ๋ฉ์๋.
- ์ฌ์ฉ์์ ์ ๋ ฅ๊ฐ์ split("")๋ก ํ ๋ฌธ์์ฉ ์ชผ๊ฐ์ด ๋ฐฐ์ด๋ก ๋ง๋ฆ
- ๊ฒฐ๊ณผ๊ฐ์ ๋ด์ ArrayList์ธ inputList๋ฅผ ์ ์ธ.
- ๊ฐ ์์๊ฐ ' ๋๋ 2์ ์ผ์นํ๋ฉด, ๊ทธ ์์์ ์ง์ ์์์ ' ๋๋ 2๋ฅผ ๋ถ์.
- ๊ฐ ์์๊ฐ '๋ ์๋๊ณ 2๋ ์๋ ๋๋ง inputList์ ์ถ๊ฐ.
- return : inputList
-
checkInput(inputList) : ์ฌ์ฉ์๋ก๋ถํฐ ์ ๋ ฅ๋ฐ์ ๋ช ๋ น์ด๋ฅผ ๊ฒ์ฌํ๋ ๋ฉ์๋.
- inputList์ ๊ฐ ์์(anInput)๋ฅผ ํ๋์ฉ ํ์ธ.
- anInput์ด U U' L L' F F' R R' B B' D D' U2 L2 F2 R2 B2 D2 ์ค ํ๋์ผ ๋๋ง guideInput(anInput) ํธ์ถ.
- ๊ทธ๋ ์ง ์์ ๋๋ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๊ณ start()-trimInput()-checkInput()์ ๋ค์ ์คํ.
- inputList์ ๋ชจ๋ ๋ช ๋ น์ด ์ฒ๋ฆฌ๊ฐ ์๋ฃ๋๋ฉด isComplete()๋ก ํ๋ธ๊ฐ ์์ฑ๋์๋์ง ํ์ธํ๊ณ ready()ํธ์ถ.
-
isComplete() : ํ๋ธ๊ฐ ์์ฑ๋์๋์ง ๊ฒ์ฌํ๋ ๋ฉ์๋.
- (์ด ํ๋ก๊ทธ๋จ์์๋) ํ๋ธ์ 6๋ฉด์ ๊ฐ์ด๋ฐ ์์(์ด์ฐจ์๋ฐฐ์ด๋ก๋ [1][1])๋ ๋ฐ๋์ ์ด๊ธฐ๊ฐ๊ณผ ๊ฐ๋ค.
- ์ฆ ์๋ฉด์ ๋ชจ๋ W, ์ผ์ชฝ ๋ฉด์ ๋ชจ๋ L, ์์ชฝ ๋ฉด์ ๋ชจ๋ G, ์ค๋ฅธ์ชฝ ๋ฉด์ ๋ชจ๋ R, ๋ท๋ฉด์ ๋ชจ๋ B, ์๋ซ๋ฉด์ ๋ชจ๋ Y์ฌ์ผ ํ๋ค.
- ๊ฒ์ฌ ๋ฐฉ๋ฒ : ์ด๊ธฐ ํ๋ธ์ ๋๊ฐ์ ์์ํ๋ธ๋ฅผ ๋ง๋ค๊ณ , ํ์ฌ ํ๋ธ์ 6๋ฉด์ด ์์ํ๋ธ์ 6๋ฉด๊ณผ ๊ฐ์์ง ๋น๊ตํ๋ค.
- ๋ง์ฝ ์์ฑ๋์๋ค๋ฉด ์ถํ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ ๋ค terminate()๋ฅผ ํธ์ถ.
-
terminate() : ํ๋ก๊ทธ๋จ ์ข ๋ฃ ๋ฉ์๋
- Scanner๋ฅผ ๋ซ๊ณ calTime()์ ํธ์ถํด ๊ฒฝ๊ณผ์๊ฐ(๋ฐ๋ฆฌ์ด ๋จ์)์ ๋ฐ๋๋ค.
- ๋ฐ์ ๊ฒฝ๊ณผ์๊ฐ์ ๋ถ, ์ด ๋จ์๋ก ๊ณ์ฐํด ์ถ๋ ฅํ๋ค.
- countNum์ ์ ์ฅ๋ ์กฐ์ํ์๋ฅผ ์ถ๋ ฅํ๋ค.
- ํ๋ก๊ทธ๋จ์ ์ข ๋ฃํ๋ค.
-
calTime() : ๊ฒฝ๊ณผ์๊ฐ์ ๊ณ์ฐํ๋ ๋ฉ์๋.
- countTime์ ์ ์ฅ๋ ์์์๊ฐ์ ๋ฐ์์จ๋ค. (์์์๊ฐ์ scramble()์์ ์ ์ฅ๋จ)
- calTime()์ด ํธ์ถ๋ ์๊ฐ์ ์ข ๋ฃ์๊ฐ์ผ๋ก ํ๋ค.
- timeGap : ์ข ๋ฃ์๊ฐ - ์์์๊ฐ (๋ฐ๋ฆฌ์ด ๋จ์)์ ๊ณ์ฐํ ๊ฒฐ๊ณผ๊ฐ
- return : timeGap
-
guideInput(anInput) : ์ฌ์ฉ์์ ๋ช ๋ น์ด ํ๋์ ๋ํ ํ๋ธํ์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ๋ฉ์๋.
- ๊ฐ ํ๋ธํ์ ๋ฉ์๋๋ค์ ๋๊ธธ ํ๋ผ๋ฏธํฐ์ธ temp์์ํ๋ธ(์๋ฉด,์ผ์ชฝ๋ฉด,์๋ฉด,์ค๋ฅธ์ชฝ๋ฉด,๋ท๋ฉด,์๋ซ๋ฉด)๋ฅผ ์ ์ธ
- switch-case๋ฌธ์ ํตํด anInput๊ณผ ์ผ์นํ๋ ํ๋ธํ์ ๋ฉ์๋๋ก ์ฐ๊ฒฐํ๊ณ , ์ ๋ ฅ๊ฐ์ ๋ํ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅ
- U2์ฒ๋ผ 1/2๋ฐํด ํ์ ํ๋ ๋ช ๋ น์ด๋ whenU()๋ฅผ ๋ ๋ฒ ํธ์ถ.
- ๊ฐ ํ๋ธํ์ ๋ฉ์๋ ์ฒ๋ฆฌ๊ฐ ๋๋๋ฉด countNum(์กฐ์ํ์) ์ 1์ ๋ํ๊ณ , ํ์ฌ ํ๋ธ๋ฅผ ์ถ๋ ฅ
-
copyToTemp(temp) / copyToCube(temp) : ์์ํ๋ธ์ ํ์ฌ ํ๋ธ๋ฅผ ๋ณต์ฌํ๋ ๋ฉ์๋.
- 6๋ฉด์ ์์ํ๋ธ ๊ฐ์ ๋ฐ์ ํ์ฌ ํ๋ธ์ ๋ณต์ฌํ๊ฑฐ๋ / ํ์ฌ ํ๋ธ 6๋ฉด์ ๊ฐ์ ์์ํ๋ธ์ ๋ณต์ฌํ๋ ๋ฉ์๋
- ๋ชจ๋ ํ๋ธํ์ ๋ฉ์๋์ ํ์ํ ๋ฉ์๋
-
clockWise(temp, cube) / counterClockWise(temp, cube) :
- ์ด๋ค ๋ฉด์ ์๊ณ๋ฐฉํฅ / ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ํ๋ ๋ฉ์๋.
- ์ด๋ค ๋ฉด์ ํ์ฌ ํ๋ธ๋ฅผ ์๊ณ๋ฐฉํฅ / ๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก 1/4 ํ์ ํด ์์ํ๋ธ์ ๋์ ํจ.
- ๋ชจ๋ ํ๋ธํ์ ๋ฉ์๋์ ํ์ํ ๋ฉ์๋
-
[ํ๋ธํ์ ๋ฉ์๋]
- whenU(temp), whenUDot(temp),whenL(temp), whenLDot(temp),whenF(temp), whenFDot(temp),
- whenR(temp), whenRDot(temp),whenB(temp), whenBDot(temp),whenD(temp), whenDDot(temp),
- ๋ช ๋ น์ด์ ๋ฐ๋ผ ํ๋ธ๋ฅผ ํ์ ์ํค๋ ๋ฉ์๋๋ค.
- ๋ชจ๋ ๋ณ๊ฒฝ์ฌํญ์ ์์ํ๋ธ์ ๋จผ์ ์ ์ฉ๋๊ณ , ๋ณ๊ฒฝ๋ ๋ด์ฉ์ด ํ์ฌ ํ๋ธ์ ๋ณต์ฌ๋๋ค.
- (1) ์์ํ๋ธ์ ํ์ฌ ํ๋ธ ๋ด์ฉ์ ๋ณต์ฌํด ๋ฃ๋๋ค
- why? ํ๋ธํ์ ๋ฉ์๋์์ ์กฐ์๋๋ ์์๋ฅผ ์ ์ธํ ์์๋ค์ ๊ทธ๋๋ก์ฌ์ผ ํ๊ธฐ ๋๋ฌธ
- (2) ๊ฐ ํ์ ๋ฉ์๋์ ํ์ ํ๋ ๋ฉด์ ์๊ณ๋ฐฉํฅ/๋ฐ์๊ณ๋ฐฉํฅ์ผ๋ก ํ์ ์ํจ ๊ฒฐ๊ณผ๋ฅผ ์์ํ๋ธ์ ์ ์ฅํ๋ค.
- ์๊ณ๋ฐฉํฅ์ด๋ฉด clockWise(temp, cube), ๋ฐ์๊ณ๋ฐฉํฅ์ด๋ฉด counterClockWise(temp, cube)
- (3) ํ์ ํ๋ ๋ฉด์ ์ธ์ ํ 4๋ฉด์ ๋ํ ๋ณ๊ฒฝ์ฌํญ์ ์กฐ์ํ์ฌ ์์ํ๋ธ์ ์ ์ฅํ๋ค. = (4) ์์ํ๋ธ์ ์ ์ฅ๋ ๋ด์ฉ์ด ํ์ฌ ํ๋ธ ์ํ๊ฐ ๋๋๋ก ๋ณต์ฌํด ๋ฃ๋๋ค.