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

Solver works, automate rotations fixed

parent d6d82d3b
......@@ -63,7 +63,7 @@ Material:
- _GlossMapScale: 1
- _Glossiness: 1
- _GlossyReflections: 0
- _Metallic: 0.39
- _Metallic: 0.534
- _Mode: 0
- _OcclusionStrength: 0.074
- _Parallax: 0.08
......
......@@ -397,12 +397,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d68921af159b33d4082d3f0389cbc2d9, type: 3}
m_Name:
m_EditorClassIdentifier:
front: []
back: []
up: []
down: []
left: []
right: []
cubemap: {fileID: 981341155}
--- !u!114 &22452984
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -446,7 +441,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4e2407f613e40544d94d16109d7c0cd0, type: 3}
m_Name:
m_EditorClassIdentifier:
moveList: []
rubicsCube: {fileID: 22452980}
cubeMap: {fileID: 981341155}
--- !u!114 &22452987
......
......@@ -6,13 +6,14 @@ using UnityEngine;
//UROBIT setters a getters!!!
public class Automate : MonoBehaviour
{
public List<string> moveList = new List<string>() { };
private static List<string> moveList = new List<string>() { };
public GameObject rubicsCube;
public GameObject cubeMap;
//static List<string> undoMoveList = new List<string>() { };
public static int actualPosition = 0;
public static bool shuffleDone = false;
bool AutomatePlaying = false;
//bool automateRotation = false;
//CubeMapMatrix cubeMap;
Colors side = Colors.Blue;
private GameObject movingParts;
......@@ -20,6 +21,7 @@ public class Automate : MonoBehaviour
private Vector3 targetVector;
private float progressOfRotation;
private float speed = 300f;
private float angle = 0;
private readonly List<string> allMoves = new List<string>()
{ "U", "D", "L", "R", "F", "B",
......@@ -49,18 +51,18 @@ public class Automate : MonoBehaviour
void Update()
{
if (AutomatePlaying)
if (CubeState.autoRotating)
{
movingParts.transform.RotateAround(Vector3.zero, targetVector, 9f);
progressOfRotation += 10;
print(progressOfRotation + " : " + Time.deltaTime);
movingParts.transform.RotateAround(Vector3.zero, targetVector, angle/20);
progressOfRotation += 5;
//print(progressOfRotation + " : " + Time.deltaTime);
if(progressOfRotation == 100)
{
foreach (Transform child in movingParts.transform)
{
child.position = new Vector3(Mathf.Round(child.position.x), Mathf.Round(child.position.y), Mathf.Round(child.position.z));
}
AutomatePlaying = false;
CubeState.autoRotating = false;
Rotator.Update2DMap(movingParts, cubeMap);
var childsToEdit = new List<Transform>();
......@@ -73,12 +75,14 @@ public class Automate : MonoBehaviour
}
if (moveList.Count > 0 && !AutomatePlaying && CubeState.started && (shuffleDone) && actualPosition < moveList.Count)
if (moveList.Count > 0 && !CubeState.autoRotating && CubeState.started && actualPosition < moveList.Count)
{
print("1");
//v if bolo shuffledone
//print("1");
//do the move at the first index;
DoMove(moveList[actualPosition]);
print(moveList[actualPosition]);
actualPosition += 1;
//remove the move at the first index
......@@ -87,7 +91,7 @@ public class Automate : MonoBehaviour
if (shuffleDone && actualPosition == moveList.Count)
{
print("2");
//print("2");
shuffleDone = false;
actualPosition = 0;
......@@ -241,16 +245,16 @@ public class Automate : MonoBehaviour
//{
// RotateSide(cubeState.back, -180);
//}
int angle = 0;
//int angle = 0;
switch (move)
{
case "R":
side = Colors.Orange;
angle = -90;
angle = 90;
break;
case "R'":
side = Colors.Orange;
angle = 90;
angle = -90;
break;
case "R2":
side = Colors.Orange;
......@@ -258,11 +262,11 @@ public class Automate : MonoBehaviour
break;
case "L":
side = Colors.Red;
angle = -90;
angle = 90;
break;
case "L'":
side = Colors.Red;
angle = 90;
angle = -90;
break;
case "L2":
side = Colors.Red;
......@@ -270,11 +274,11 @@ public class Automate : MonoBehaviour
break;
case "F":
side = Colors.Blue;
angle = -90;
angle = 90;
break;
case "F'":
side = Colors.Blue;
angle = 90;
angle = -90;
break;
case "F2":
side = Colors.Blue;
......@@ -282,11 +286,11 @@ public class Automate : MonoBehaviour
break;
case "B":
side = Colors.Green;
angle = -90;
angle = 90;
break;
case "B'":
side = Colors.Green;
angle = 90;
angle = -90;
break;
case "B2":
side = Colors.Green;
......@@ -294,11 +298,11 @@ public class Automate : MonoBehaviour
break;
case "U":
side = Colors.White;
angle = -90;
angle = 90;
break;
case "U'":
side = Colors.White;
angle = 90;
angle = -90;
break;
case "U2":
side = Colors.White;
......@@ -306,11 +310,11 @@ public class Automate : MonoBehaviour
break;
case "D":
side = Colors.Yellow;
angle = -90;
angle = 90;
break;
case "D'":
side = Colors.Yellow;
angle = 90;
angle = -90;
break;
case "D2":
side = Colors.Yellow;
......@@ -338,8 +342,8 @@ public class Automate : MonoBehaviour
// set parent back
foreach (Transform child in childsToEdit)
child.SetParent(movingParts.transform);
print(movingParts.transform.childCount + " hehe");
RotateSide(angle);
//print(movingParts.transform.childCount + " hehe");
RotateSide();
......@@ -409,7 +413,7 @@ public class Automate : MonoBehaviour
}
void RotateSide(float angle)
void RotateSide()
{
//automatically rotate the side by the angle
//PivotRotation pr = centre.transform.parent.GetComponent<PivotRotation>();
......@@ -442,8 +446,13 @@ public class Automate : MonoBehaviour
// child.position = new Vector3(Mathf.Round(child.position.x), Mathf.Round(child.position.y), Mathf.Round(child.position.z));
//}
AutomatePlaying = true;
CubeState.autoRotating = true;
progressOfRotation = 0;
targetVector = axis;
}
public static void setAutomateList(List<string> moves)
{
moveList = moves;
}
}
......@@ -10,7 +10,7 @@ public class CubeMap : MonoBehaviour
private int numOfFaces;
private int numOfSquaresInRowMinusOne = 2;
List<Transform> sides;
CubeMapMatrix cubeMapMatrix;
//CubeMapMatrix cubeMapMatrix;
List<Face> cubeMapM;
public Transform up;
......@@ -31,8 +31,8 @@ public class CubeMap : MonoBehaviour
// Start is called before the first frame update
void Start()
{
cubeMapMatrix = new CubeMapMatrix();
cubeMapMatrix.createMatrixAtStart();
//cubeMapMatrix = new CubeMapMatrix();
//cubeMapMatrix.createMatrixAtStart();
//cubeMapM = cubeMapMatrix.getCubeMap();
setNumberOfFaces();
......@@ -57,7 +57,7 @@ public class CubeMap : MonoBehaviour
private void setNumberOfFaces()
{
numOfFaces = cubeMapMatrix.getNumberOfFaces();
//numOfFaces = cubeMapMatrix.getNumberOfFaces();
}
// Update is called once per frame
......@@ -89,13 +89,13 @@ public class CubeMap : MonoBehaviour
void UpdateMap(int faceInCubeMap, Transform faceIn2DModel)
{
print("Update!" + faceInCubeMap);
//print("Update!" + faceInCubeMap);
int i = 0;
int row = 0;
foreach(Transform square in faceIn2DModel)
{
//print(row);
Colors colorOfSquareInCubeMap = cubeMapMatrix.getOnlyOneSquare(faceInCubeMap, row , i);
Colors colorOfSquareInCubeMap = Colors.Blue;//cubeMapMatrix.getOnlyOneSquare(faceInCubeMap, row , i);
switch (colorOfSquareInCubeMap)
{
......
This diff is collapsed.
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CubeState : MonoBehaviour
{
//sides
public List<GameObject> front = new List<GameObject>();
public List<GameObject> back = new List<GameObject>();
public List<GameObject> up = new List<GameObject>();
public List<GameObject> down = new List<GameObject>();
public List<GameObject> left = new List<GameObject>();
public List<GameObject> right = new List<GameObject>();
//public List<GameObject> front = new List<GameObject>();
//public List<GameObject> back = new List<GameObject>();
//public List<GameObject> up = new List<GameObject>();
//public List<GameObject> down = new List<GameObject>();
//public List<GameObject> left = new List<GameObject>();
//public List<GameObject> right = new List<GameObject>();
public GameObject cubemap;
public static bool autoRotating = false;
public static bool started = false;
......@@ -55,28 +59,85 @@ public class CubeState : MonoBehaviour
}
}
string GetSideString(List<GameObject> side)
{
string sideString = "";
foreach (GameObject face in side)
{
sideString += face.name[0].ToString();
}
//string GetSideString(List<GameObject> side)
//{
// string sideString = "";
// foreach (GameObject face in side)
// {
// sideString += face.name[0].ToString();
// }
return sideString;
}
// return sideString;
//}
public string GetStateString()
{
string stateString = "";
stateString += GetSideString(up);
stateString += GetSideString(left);
stateString += GetSideString(front);
stateString += GetSideString(right);
stateString += GetSideString(back);
stateString += GetSideString(down);
return stateString;
string[] stateString = new string[54];
int position = 0;
string colorOfPlane = "";
foreach(Transform side in cubemap.transform)
{
foreach(Transform plane in side.transform)
{
switch (side.name)
{
case "Front":
position = 18 + Int32.Parse(plane.name);
break;
case "Back":
position = 36 + Int32.Parse(plane.name);
break;
case "Right":
position = 27 + Int32.Parse(plane.name);
break;
case "Left":
position = 9 + Int32.Parse(plane.name);
break;
case "Up":
position = 0 + Int32.Parse(plane.name);
break;
case "Down":
position = 45 + Int32.Parse(plane.name);
break;
default:
print("smth wrong");
break;
}
//print(position);
switch (plane.tag)
{
case "B":
stateString[position] = "F";
break;
case "G":
stateString[position] = "B";
break;
case "R":
stateString[position] = "L";
break;
case "O":
stateString[position] = "R";
break;
case "W":
stateString[position] = "U";
break;
case "Y":
stateString[position] = "D";
break;
}
}
}
//stateString += GetSideString(up);
//stateString += GetSideString(left);
//stateString += GetSideString(front);
//stateString += GetSideString(right);
//stateString += GetSideString(back);
//stateString += GetSideString(down);
return string.Join("", stateString);
}
......
......@@ -4,28 +4,29 @@ using System.Collections.Generic;
public class Face
{
private int numOfRows = 3;
//Row row1;
//Row row2;
//Row row3;
Row[] rows;
//private int numOfRows = 3;
public char[] row1 = new char [3];
public char[] row2 = new char[3];
public char[] row3 = new char[3];
//Row[] rows;
public Face(Colors color)
{
rows = new Row[numOfRows];
for (int i = 0; i < numOfRows; i++)
{
rows[i] = (new Row(color));
}
//this.row1 = new Row(color);
//this.row2 = new Row(color);
//this.row3 = new Row(color);
}
public Row getRow(int row)
{
return rows[row];
}
//public Face(Colors color)
//{
// rows = new Row[numOfRows];
// for (int i = 0; i < numOfRows; i++)
// {
// rows[i] = (new Row(color));
// }
// //this.row1 = new Row(color);
// //this.row2 = new Row(color);
// //this.row3 = new Row(color);
//}
//public Row getRow(int row)
//{
// return rows[row];
//}
}
......@@ -23,7 +23,7 @@ public class ReadCube : MonoBehaviour
CubeState cubeState;
CubeMap cubeMap;
public GameObject emptyGO;
CubeMapMatrix cubeMapMatrix;
//CubeMapMatrix cubeMapMatrix;
// Start is called before the first frame update
void Start()
......
......@@ -15,14 +15,15 @@ public class Rotator : MonoBehaviour
private bool autoRotating = false;
private Vector3 rotatingDestination = new Vector3();
private CubeMapMatrix cubemap;
//private CubeMapMatrix cubemap;
private Quaternion targetQuaternion;
// Start is called before the first frame update
void Start()
{
movingParts = new GameObject();
cubemap = new CubeMapMatrix();
//cubemap = new CubeMapMatrix();
Update2DMap(rubicsCube,Cubes2DMap);
}
......@@ -207,12 +208,20 @@ public class Rotator : MonoBehaviour
else
continue;
Cube2DMap
.transform.Find(side2D)
.transform.Find(index.ToString())
.transform.GetComponent<Image>()
.color = plane.GetComponent<Renderer>().material.color;
Cube2DMap
.transform.Find(side2D)
.transform.Find(index.ToString()).tag = plane.GetComponent<Renderer>().material.name[0].ToString();
}
}
......
......@@ -33,26 +33,27 @@ public class SolveTwoFace : MonoBehaviour
//get the state of the cube as a string
string moveString = cubeState.GetStateString();
//print(moveString);
print(moveString);
//solve the cube
////solve the cube
Solver solver = new Solver(moveString);
//string info = "";
//first time build the tables
////string info = "";
////first time build the tables
string solution = solver.Solve();
//convert the solved moves from a string to a list
////convert the solved moves from a string to a list
List<string> solutionList = StringToList(solution);
//Automate the list
Automate.shuffleDone = false;
//Automate.moveList = solutionList; toto uncomment
////Automate the list
//Automate.shuffleDone = false;
//Automate.setAutomateList(new List<string> { "F" } );
Automate.setAutomateList(solutionList);
Automate.actualPosition = 0;
print(solution);
}
else
{
print("CUBE IS MOVING!! STOP IT FIRST!! U LITTLE BITCH!!");
print("CUBE IS MOVING!! STOP IT FIRST!!");
}
}
......
This diff is collapsed.
......@@ -5,6 +5,12 @@ TagManager:
serializedVersion: 2
tags:
- Centre
- Y
- G
- B
- R
- O
- W
layers:
- Default
- TransparentFX
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment