Commit 6c6905d9 authored by Bošániová Monika's avatar Bošániová Monika
Browse files

Started to create new solver

parent 794be9c1
......@@ -344,7 +344,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 2e33c8fb25bdc3941b1d3dfde4ddeb9e, type: 2}
- {fileID: 2100000, guid: 008ed915e9747194d8473e08a7536708, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
......@@ -437,7 +437,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 8b908df66e033894e952ac577be7884d, type: 2}
- {fileID: 2100000, guid: 21f899676ae3b3e458ec298f4589efe4, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
......@@ -530,7 +530,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 21f899676ae3b3e458ec298f4589efe4, type: 2}
- {fileID: 2100000, guid: 8b908df66e033894e952ac577be7884d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
......@@ -623,7 +623,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 008ed915e9747194d8473e08a7536708, type: 2}
- {fileID: 2100000, guid: 2e33c8fb25bdc3941b1d3dfde4ddeb9e, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
......
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BegginerSolver
{
List<Face> cubeMatrix = new List<Face>();
readonly int numOfFaces = 6;
int numOfEdgesOnOneFace = 4;
string cubeMixed;
string finalMoves = "";
public BegginerSolver(string input)
{
cubeMixed = input;
}
public string Solve()
{
CreateCubeMatrix();
SolveFirstLayer();
return finalMoves;
}
public void CreateCubeMatrix()
{
for (int i = 0; i < cubeMixed.Length / 9; i++)
{
Face face = new Face();
int position = i * 9;
face.row0 = new char[] { cubeMixed[position], cubeMixed[position + 1], cubeMixed[position + 2] };
face.row1 = new char[] { cubeMixed[position + 3], cubeMixed[position + 4], cubeMixed[position + 5] };
face.row2 = new char[] { cubeMixed[position + 6], cubeMixed[position + 7], cubeMixed[position + 8] };
cubeMatrix.Add(face);
}
}
private void SolveFirstLayer()
{
GetEdgesFromSecondLayerToDownFace();
GetEdgesFromThirdLayerToDownFace();
}
private void GetEdgesFromSecondLayerToDownFace()
{
for (int i = 1; i <= numOfEdgesOnOneFace; i++)
{
if(cubeMatrix[i].row1[0] == 'U')
{
if(cubeMatrix[])
}
}
}
private void GetEdgesFromThirdLayerToDownFace()
{
throw new NotImplementedException();
}
//Rotations
//RIGHT
/// <summary>
///
/// </summary>
void RotationR()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row0[2]);
tmp.Add(cubeMatrix[0].row1[2]);
tmp.Add(cubeMatrix[0].row2[2]);
//up
cubeMatrix[0].row0[2] = cubeMatrix[2].row0[2];
cubeMatrix[0].row1[2] = cubeMatrix[2].row1[2];
cubeMatrix[0].row2[2] = cubeMatrix[2].row2[2];
//front
cubeMatrix[2].row0[2] = cubeMatrix[5].row0[2];
cubeMatrix[2].row1[2] = cubeMatrix[5].row1[2];
cubeMatrix[2].row2[2] = cubeMatrix[5].row2[2];
//down
cubeMatrix[5].row0[2] = cubeMatrix[4].row2[0];
cubeMatrix[5].row1[2] = cubeMatrix[4].row1[0];
cubeMatrix[5].row2[2] = cubeMatrix[4].row0[0];
//back
cubeMatrix[4].row0[0] = tmp[2];
cubeMatrix[4].row1[0] = tmp[1];
cubeMatrix[4].row2[0] = tmp[0];
finalMoves += "R ";
RotationFace(3);
}
/// <summary>
///
/// </summary>
void RotationR2()
{
RotationR();
RotationR();
}
/// <summary>
///
/// </summary>
void RotationR_()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row0[2]);
tmp.Add(cubeMatrix[0].row1[2]);
tmp.Add(cubeMatrix[0].row2[2]);
//up
cubeMatrix[0].row0[2] = cubeMatrix[4].row2[0];
cubeMatrix[0].row1[2] = cubeMatrix[4].row1[0];
cubeMatrix[0].row2[2] = cubeMatrix[4].row0[0];
//back
cubeMatrix[4].row0[0] = cubeMatrix[5].row2[2];
cubeMatrix[4].row1[0] = cubeMatrix[5].row1[2];
cubeMatrix[4].row2[0] = cubeMatrix[5].row0[2];
//down
cubeMatrix[5].row0[2] = cubeMatrix[2].row0[2];
cubeMatrix[5].row1[2] = cubeMatrix[2].row1[2];
cubeMatrix[5].row2[2] = cubeMatrix[2].row2[2];
//front
cubeMatrix[2].row0[2] = tmp[0];
cubeMatrix[2].row1[2] = tmp[1];
cubeMatrix[2].row2[2] = tmp[2];
finalMoves += "R' ";
RotationFace_(3);
}
//LEFT
/// <summary>
///
/// </summary>
void RotationL()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row0[0]);
tmp.Add(cubeMatrix[0].row1[0]);
tmp.Add(cubeMatrix[0].row2[0]);
//up
cubeMatrix[0].row0[0] = cubeMatrix[4].row2[2];
cubeMatrix[0].row1[0] = cubeMatrix[4].row1[2];
cubeMatrix[0].row2[0] = cubeMatrix[4].row0[2];
//back
cubeMatrix[4].row0[2] = cubeMatrix[5].row2[0];
cubeMatrix[4].row1[2] = cubeMatrix[5].row1[0];
cubeMatrix[4].row2[2] = cubeMatrix[5].row0[0];
//down
cubeMatrix[5].row0[0] = cubeMatrix[2].row0[0];
cubeMatrix[5].row1[0] = cubeMatrix[2].row1[0];
cubeMatrix[5].row2[0] = cubeMatrix[2].row2[0];
//front
cubeMatrix[2].row0[0] = tmp[0];
cubeMatrix[2].row1[0] = tmp[1];
cubeMatrix[2].row2[0] = tmp[2];
finalMoves += "L ";
RotationFace(1);
}
/// <summary>
///
/// </summary>
void RotationL2()
{
RotationL();
RotationL();
}
/// <summary>
///
/// </summary>
void RotationL_()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row0[0]);
tmp.Add(cubeMatrix[0].row1[0]);
tmp.Add(cubeMatrix[0].row2[0]);
//up
cubeMatrix[0].row0[0] = cubeMatrix[2].row0[0];
cubeMatrix[0].row1[0] = cubeMatrix[2].row1[0];
cubeMatrix[0].row2[0] = cubeMatrix[2].row2[0];
//front
cubeMatrix[2].row0[0] = cubeMatrix[5].row0[0];
cubeMatrix[2].row1[0] = cubeMatrix[5].row1[0];
cubeMatrix[2].row2[0] = cubeMatrix[5].row2[0];
//down
cubeMatrix[5].row0[0] = cubeMatrix[4].row2[2];
cubeMatrix[5].row1[0] = cubeMatrix[4].row1[2];
cubeMatrix[5].row2[0] = cubeMatrix[4].row0[2];
//back
cubeMatrix[4].row0[2] = tmp[2];
cubeMatrix[4].row1[2] = tmp[1];
cubeMatrix[4].row2[2] = tmp[0];
finalMoves += "L' ";
RotationFace_(1);
}
//FRONT
/// <summary>
///
/// </summary>
void RotationF()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row2[0]);
tmp.Add(cubeMatrix[0].row2[1]);
tmp.Add(cubeMatrix[0].row2[2]);
//up
cubeMatrix[0].row2[0] = cubeMatrix[1].row2[2];
cubeMatrix[0].row2[1] = cubeMatrix[1].row1[2];
cubeMatrix[0].row2[2] = cubeMatrix[1].row0[2];
//left
cubeMatrix[1].row0[2] = cubeMatrix[5].row0[0];
cubeMatrix[1].row1[2] = cubeMatrix[5].row0[1];
cubeMatrix[1].row2[2] = cubeMatrix[5].row0[2];
//down
cubeMatrix[5].row0[0] = cubeMatrix[3].row2[0];
cubeMatrix[5].row0[1] = cubeMatrix[3].row1[0];
cubeMatrix[5].row0[2] = cubeMatrix[3].row0[0];
//right
cubeMatrix[3].row0[0] = tmp[0];
cubeMatrix[3].row1[0] = tmp[1];
cubeMatrix[3].row2[0] = tmp[2];
finalMoves += "F ";
RotationFace(2);
}
/// <summary>
///
/// </summary>
void RotationF2()
{
RotationF();
RotationF();
}
/// <summary>
///
/// </summary>
void RotationF_()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row2[0]);
tmp.Add(cubeMatrix[0].row2[1]);
tmp.Add(cubeMatrix[0].row2[2]);
//up
cubeMatrix[0].row2[0] = cubeMatrix[3].row0[0];
cubeMatrix[0].row2[1] = cubeMatrix[3].row1[0];
cubeMatrix[0].row2[2] = cubeMatrix[3].row2[0];
//right
cubeMatrix[3].row0[0] = cubeMatrix[5].row0[2];
cubeMatrix[3].row1[0] = cubeMatrix[5].row0[1];
cubeMatrix[3].row2[0] = cubeMatrix[5].row0[0];
//down
cubeMatrix[5].row0[0] = cubeMatrix[1].row0[2];
cubeMatrix[5].row0[1] = cubeMatrix[1].row1[2];
cubeMatrix[5].row0[2] = cubeMatrix[1].row2[2];
//right
cubeMatrix[1].row0[2] = tmp[2];
cubeMatrix[1].row1[2] = tmp[1];
cubeMatrix[1].row2[2] = tmp[0];
finalMoves += "F' ";
RotationFace_(2);
}
//BACK
void RotationB()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row0[0]);
tmp.Add(cubeMatrix[0].row0[1]);
tmp.Add(cubeMatrix[0].row0[2]);
//up
cubeMatrix[0].row0[0] = cubeMatrix[3].row0[2];
cubeMatrix[0].row0[1] = cubeMatrix[3].row1[2];
cubeMatrix[0].row0[2] = cubeMatrix[3].row2[2];
//right
cubeMatrix[3].row0[2] = cubeMatrix[5].row2[2];
cubeMatrix[3].row1[2] = cubeMatrix[5].row2[1];
cubeMatrix[3].row2[2] = cubeMatrix[5].row2[0];
//down
cubeMatrix[5].row2[0] = cubeMatrix[1].row0[0];
cubeMatrix[5].row2[1] = cubeMatrix[1].row1[0];
cubeMatrix[5].row2[2] = cubeMatrix[1].row2[0];
//right
cubeMatrix[1].row0[0] = tmp[2];
cubeMatrix[1].row1[0] = tmp[1];
cubeMatrix[1].row2[0] = tmp[0];
finalMoves += "B ";
RotationFace(4);
}
/// <summary>
///
/// </summary>
void RotationB2()
{
RotationB();
RotationB();
}
/// <summary>
///
/// </summary>
void RotationB_()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[0].row0[0]);
tmp.Add(cubeMatrix[0].row0[1]);
tmp.Add(cubeMatrix[0].row0[2]);
//up
cubeMatrix[0].row0[0] = cubeMatrix[1].row2[0];
cubeMatrix[0].row0[1] = cubeMatrix[1].row1[0];
cubeMatrix[0].row0[2] = cubeMatrix[1].row0[0];
//left
cubeMatrix[1].row0[0] = cubeMatrix[5].row2[0];
cubeMatrix[1].row1[0] = cubeMatrix[5].row2[1];
cubeMatrix[1].row2[0] = cubeMatrix[5].row2[2];
//down
cubeMatrix[5].row2[0] = cubeMatrix[3].row2[2];
cubeMatrix[5].row2[1] = cubeMatrix[3].row1[2];
cubeMatrix[5].row2[2] = cubeMatrix[3].row0[2];
//right
cubeMatrix[3].row0[2] = tmp[0];
cubeMatrix[3].row1[2] = tmp[1];
cubeMatrix[3].row2[2] = tmp[2];
finalMoves += "B' ";
RotationFace_(4);
}
//UP
/// <summary>
///
/// </summary>
void RotationU()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[2].row0[0]);
tmp.Add(cubeMatrix[2].row0[1]);
tmp.Add(cubeMatrix[2].row0[2]);
//front
cubeMatrix[2].row0[0] = cubeMatrix[3].row0[0];
cubeMatrix[2].row0[1] = cubeMatrix[3].row0[1];
cubeMatrix[2].row0[2] = cubeMatrix[3].row0[2];
//right
cubeMatrix[3].row0[0] = cubeMatrix[4].row0[0];
cubeMatrix[3].row0[1] = cubeMatrix[4].row0[1];
cubeMatrix[3].row0[2] = cubeMatrix[4].row0[2];
//back
cubeMatrix[4].row0[0] = cubeMatrix[1].row0[0];
cubeMatrix[4].row0[1] = cubeMatrix[1].row0[1];
cubeMatrix[4].row0[2] = cubeMatrix[1].row0[2];
//left
cubeMatrix[1].row0[0] = tmp[0];
cubeMatrix[1].row0[1] = tmp[1];
cubeMatrix[1].row0[2] = tmp[2];
finalMoves += "U ";
RotationFace(0);
}
/// <summary>
///
/// </summary>
void RotationU2()
{
RotationU();
RotationU();
}
/// <summary>
///
/// </summary>
void RotationU_()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[2].row0[0]);
tmp.Add(cubeMatrix[2].row0[1]);
tmp.Add(cubeMatrix[2].row0[2]);
//front
cubeMatrix[2].row0[0] = cubeMatrix[1].row0[0];
cubeMatrix[2].row0[1] = cubeMatrix[1].row0[1];
cubeMatrix[2].row0[2] = cubeMatrix[1].row0[2];
//right
cubeMatrix[1].row0[0] = cubeMatrix[4].row0[0];
cubeMatrix[1].row0[1] = cubeMatrix[4].row0[1];
cubeMatrix[1].row0[2] = cubeMatrix[4].row0[2];
//back
cubeMatrix[4].row0[0] = cubeMatrix[3].row0[0];
cubeMatrix[4].row0[1] = cubeMatrix[3].row0[1];
cubeMatrix[4].row0[2] = cubeMatrix[3].row0[2];
//left
cubeMatrix[3].row0[0] = tmp[0];
cubeMatrix[3].row0[1] = tmp[1];
cubeMatrix[3].row0[2] = tmp[2];
finalMoves += "U' ";
RotationFace_(0);
}
//DOWN
/// <summary>
///
/// </summary>
void RotationD()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[2].row2[0]);
tmp.Add(cubeMatrix[2].row2[1]);
tmp.Add(cubeMatrix[2].row2[2]);
//front
cubeMatrix[2].row2[0] = cubeMatrix[1].row2[0];
cubeMatrix[2].row2[1] = cubeMatrix[1].row2[1];
cubeMatrix[2].row2[2] = cubeMatrix[1].row2[2];
//right
cubeMatrix[1].row2[0] = cubeMatrix[4].row2[0];
cubeMatrix[1].row2[1] = cubeMatrix[4].row2[1];
cubeMatrix[1].row2[2] = cubeMatrix[4].row2[2];
//back
cubeMatrix[4].row2[0] = cubeMatrix[3].row2[0];
cubeMatrix[4].row2[1] = cubeMatrix[3].row2[1];
cubeMatrix[4].row2[2] = cubeMatrix[3].row2[2];
//left
cubeMatrix[3].row2[0] = tmp[0];
cubeMatrix[3].row2[1] = tmp[1];
cubeMatrix[3].row2[2] = tmp[2];
finalMoves += "D ";
RotationFace(5);
}
/// <summary>
///
/// </summary>
void RotationD2()
{
RotationD();
RotationD();
}
/// <summary>
///
/// </summary>
void RotationD_()
{
List<char> tmp = new List<char>();
tmp.Add(cubeMatrix[2].row2[0]);
tmp.Add(cubeMatrix[2].row2[1]);
tmp.Add(cubeMatrix[2].row2[2]);
//front
cubeMatrix[2].row2[0] = cubeMatrix[3].row2[0];
cubeMatrix[2].row2[1] = cubeMatrix[3].row2[1];
cubeMatrix[2].row2[2] = cubeMatrix[3].row2[2];
//right
cubeMatrix[3].row2[0] = cubeMatrix[4].row2[0];
cubeMatrix[3].row2[1] = cubeMatrix[4].row2[1];
cubeMatrix[3].row2[2] = cubeMatrix[4].row2[2];
//back
cubeMatrix[4].row2[0] = cubeMatrix[1].row2[0];
cubeMatrix[4].row2[1] = cubeMatrix[1].row2[1];
cubeMatrix[4].row2[2] = cubeMatrix[1].row2[2];
//left
cubeMatrix[1].row2[0] = tmp[0];
cubeMatrix[1].row2[1] = tmp[1];
cubeMatrix[1].row2[2] = tmp[2];
finalMoves += "D' ";
RotationFace_(5);
}
void RotationFace(int numOfFace)
{
char tmp = cubeMatrix[numOfFace].row0[0];
char tmps = cubeMatrix[numOfFace].row0[1];
cubeMatrix[numOfFace].row0[0] = cubeMatrix[numOfFace].row2[0];
cubeMatrix[numOfFace].row2[0] = cubeMatrix[numOfFace].row2[2];
cubeMatrix[numOfFace].row2[2] = cubeMatrix[numOfFace].row0[2];
cubeMatrix[numOfFace].row0[2] = tmp;
cubeMatrix[numOfFace].row0[1] = cubeMatrix[numOfFace].row1[0];
cubeMatrix[numOfFace].row1[0] = cubeMatrix[numOfFace].row2[1];
cubeMatrix[numOfFace].row2[1] = cubeMatrix[numOfFace].row1[2];
cubeMatrix[numOfFace].row1[2] = tmps;
}