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

LaTex update, iterator added

parent 763f649a
......@@ -7,6 +7,8 @@ using UnityEngine;
public class Automate : MonoBehaviour
{
private static List<string> moveList = new List<string>() { };
private static MovesCollection movelist = new MovesCollection();
private static MovesIterator movelistIterator = new MovesIterator(movelist);
public GameObject rubicsCube;
public GameObject cubeMap;
public GameObject ClickableRotator;
......@@ -40,12 +42,6 @@ public class Automate : MonoBehaviour
//cubeMap = CubeMapMatrix.CubeMatrix;
CubeState.started = true;
movingParts = new GameObject();
//readCube = FindObjectOfType<ReadCube>();
////update 2D Map
//CubeMapMatrix.createMatrixAtStart();
//CubeMap cubeMap = FindObjectOfType<CubeMap>();
//cubeMap.Set();
}
// Update is called once per frame
......@@ -56,7 +52,6 @@ public class Automate : MonoBehaviour
{
movingParts.transform.RotateAround(Vector3.zero, targetVector, angle/20);
progressOfRotation += 5;
//print(progressOfRotation + " : " + Time.deltaTime);
if(progressOfRotation == 100)
{
foreach (Transform child in movingParts.transform)
......@@ -75,37 +70,21 @@ public class Automate : MonoBehaviour
}
}
if (moveList.Count > 0 && !CubeState.autoRotating && CubeState.started && AutomatePlaying && actualPosition < moveList.Count)
if (movelist.getItems().Count > 0 && !CubeState.autoRotating && CubeState.started && AutomatePlaying && movelistIterator.MoveNext())
{
//v if bolo shuffledone
//print("1");
//do the move at the first index;
DoMove(moveList[actualPosition]);
//print(moveList[actualPosition]);
actualPosition += 1;
//ClickableRotator.SetActive(false);
DoMove(movelistIterator.Current().ToString());
//remove the move at the first index
//moveList.Remove(moveList[0]);
}
if (actualPosition == moveList.Count)
{
//shuffleDone remove from if
//print("2");
shuffleDone = false;
actualPosition = 0;
moveList.Clear();
//ClickableRotator.SetActive(true);
}
}
public void AutomatePlayStart()
{
if(moveList.Count > 0)
if(movelist.getItems().Count > 0)
AutomatePlaying = true;
}
......@@ -117,31 +96,38 @@ public class Automate : MonoBehaviour
public void ForwardMove()
{
AutomatePlaying = false;
if (moveList.Count > 0 && !CubeState.autoRotating && CubeState.started && actualPosition != moveList.Count)
if (movelist.getItems().Count > 0 && !CubeState.autoRotating && CubeState.started && movelistIterator.Key() != movelist.getItems().Count -1)
{
//do the move at the first index;
DoMove(moveList[actualPosition]);
actualPosition += 1;
print("Forward:" + moveList.Count + (actualPosition -1));
//remove the move at the first index
//moveList.Remove(moveList[0]);
if (movelistIterator.MoveNext())
{
DoMove(movelistIterator.Current().ToString());
print(movelistIterator.Key().ToString() + " : " + movelistIterator.Current().ToString());
}
}
}
public void UndoMove()
{
AutomatePlaying = false;
if (moveList.Count > 0 && !CubeState.autoRotating && CubeState.started && actualPosition != 0)
if(movelist.getItems().Count > 0 && !CubeState.autoRotating && CubeState.started && movelistIterator.Key() != -1)
{
//do the move at the first index;
DoOppositeMove(moveList[actualPosition - 1]);
actualPosition -= 1;
print("Undo:" + moveList.Count + (actualPosition + 1));
//remove the move at the first index
//undoMoveList.Remove(undoMoveList[0]);
DoOppositeMove(movelistIterator.Current().ToString());
print(movelistIterator.Key().ToString() + " : " + movelistIterator.Current().ToString());
if (!movelistIterator.MoveBack())
{
movelistIterator.Reset();
}
}
}
public void Shuffle()
{
......@@ -153,16 +139,17 @@ public class Automate : MonoBehaviour
int randomMove = UnityEngine.Random.Range(0, allMoves.Count);
moves.Add(allMoves[randomMove]);
}
moveList = moves;
movelist.AddCollection(moves);
movelistIterator.Reset();
string tmp = "";
for (int i = 0; i < moveList.Count; i++)
foreach (var m in movelist)
{
tmp += moveList[i];
tmp += m;
tmp += " ";
}
print(tmp);
shuffleDone = true;
actualPosition = 0;
//actualPosition = 0;
//ClickableRotator.SetActive(false);
AutomatePlaying = true;
......@@ -364,6 +351,8 @@ public class Automate : MonoBehaviour
public static void setAutomateList(List<string> moves)
{
moveList = moves;
movelist.AddCollection(moves);
movelistIterator.Reset();
//moveList = moves;
}
}
using System.Collections;
using System.Collections.Generic;
abstract class Iterator : IEnumerator
{
object IEnumerator.Current => Current();
// Returns the key of the current element
public abstract int Key();
// Returns the current element
public abstract object Current();
// Move forward to next element
public abstract bool MoveNext();
//Move one step back
public abstract bool MoveBack();
public abstract void Reset();
}
abstract class IteratorAggregate : IEnumerable
{
// Returns an Iterator or another IteratorAggregate for the implementing
// object.
public abstract IEnumerator GetEnumerator();
}
class MovesIterator : Iterator
{
private MovesCollection _collection;
// Stores the current traversal position. An iterator may have a lot of
// other fields for storing iteration state, especially when it is
// supposed to work with a particular kind of collection.
private int _position = -1;
//private bool _reverse = false;
public MovesIterator(MovesCollection collection)
{
this._collection = collection;
//this._reverse = reverse;
}
public override object Current()
{
return this._collection.getItems()[_position];
}
public override int Key()
{
return this._position;
}
public override bool MoveNext()
{
int updatedPosition = this._position + 1;
if (updatedPosition >= 0 && updatedPosition < this._collection.getItems().Count)
{
this._position = updatedPosition;
return true;
}
else
{
return false;
}
}
public override bool MoveBack()
{
int updatedPosition = this._position - 1;
if (updatedPosition >= 0 && updatedPosition < this._collection.getItems().Count)
{
this._position = updatedPosition;
return true;
}
else
{
return false;
}
}
public override void Reset()
{
this._position = -1;
}
}
// Concrete Collections provide one or several methods for retrieving fresh
// iterator instances, compatible with the collection class.
class MovesCollection : IteratorAggregate
{
List<string> _collection = new List<string>();
bool _direction = false;
public List<string> getItems()
{
return _collection;
}
public void AddItem(string item)
{
this._collection.Add(item);
}
public void AddCollection(List<string> col)
{
this._collection = col;
}
public void ClearCollection()
{
this._collection.Clear();
}
public override IEnumerator GetEnumerator()
{
return new MovesIterator(this);
}
}
......@@ -4,9 +4,73 @@ ktorými sme sa pri implementácii potýkali.
Rovnako nahliadneme na ich výhody a nevýhody. Porovnáme ich efektivitu a vhodnosť z hľadiska
cieľov projektu.
\section{Existujúce projekty a riešiče}
Hlavolam Rubikova kocka
Existuje veľa spôsobov ako zložiť Rubikovu kocku. Od úplného začiatočníckeho princípu až po
profesionálny. Keď užívateľ drží po prvýkrát tento hlavolam v rukách, väčšinou sa zasekne
po dokončení jednej zo strán. Preto existuje mnoho spísaných algoritmov, ktoré slúžia ako pomoc
začiatočníckym riešiteľom. V tejto kapitole si ukážeme jednoduché spôsoby rišenia, ale aj tie pokročilejšie.
\subsection{Kociemba}
Jeden z najznámejších algoritmov na skladanie Rubikovej kocky je Kociemba.
\subsection{Začiatočnícky spôsob riešenia}
Aby sme vysvetlili začiatočníkom, ako poskladať tento hlavom, musíme postupovať po jednotlivých krokoch.
Budeme skladať kocku po vrstvách a ukazovať jednotlivé sekvencie ťahov, ktoré nás vždy posunú o vrstvu ďalej.
Základnou myšlienkou je, aby sme ukázali užívateľovi progres, ktorý doteraz poskladal.
Budeme opisovať algoritmus z tejto stránky \url https://ruwix.com/the-rubiks-cube/how-to-solve-the-rubiks-cube-beginners-method/
Pri opise algoritmu, budeme používať spomínanú notáciu v kapitole (ref).
Spoločne prejdeme všetkými siedmimi krokmi.
Výber steny, ktorou budeme začínať, nemá pre začiatočníka nejaký vplyv na efektivitu riešenia. Preto všeobecne väčšina
algoritmov ľahkej úrovne vybrala predvolene bielu farbu. Opísaný postup nižšie nebude výnimkou.
\\
1. Biele hrany\\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/1.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/1.svg}]{Model Rubikovej kocky}
\end{figure}
2. Biele rohy \\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/3.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/3.svg}]{Model Rubikovej kocky}
\end{figure}
3. Druhá vrstva\\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/7.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/7.svg}]{Model Rubikovej kocky}
\end{figure}
4. Žlté hrany\\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/12.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/12.svg}]{Model Rubikovej kocky}
\end{figure}
5. Orientácia žltých hrán\\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/13.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/13.svg}]{Model Rubikovej kocky}
\end{figure}
6. Permutácia spodných rohov\\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/16.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/16.svg}]{Model Rubikovej kocky}
\end{figure}
7. Otočenie spodných rohov\\
\begin{figure}[H]
\centering
\includegraphics[width=.3\linewidth]{img/17.png}
\caption[Model Rubikovej kocky \url{https://ruwix.com/pics/solution/17.svg}]{Model Rubikovej kocky}
\end{figure}
\section{Užívateľské prostredie}
\subsection{Kamera}
......
......@@ -80,15 +80,15 @@
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool>LaTeX with hyperref</xmp:CreatorTool>
<xmp:ModifyDate>2021-07-16T02:07:08+02:00</xmp:ModifyDate>
<xmp:CreateDate>2021-07-16T02:07:08+02:00</xmp:CreateDate>
<xmp:MetadataDate>2021-07-16T02:07:08+02:00</xmp:MetadataDate>
<xmp:ModifyDate>2021-07-16T22:57:12+02:00</xmp:ModifyDate>
<xmp:CreateDate>2021-07-16T22:57:12+02:00</xmp:CreateDate>
<xmp:MetadataDate>2021-07-16T22:57:12+02:00</xmp:MetadataDate>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmpRights = "http://ns.adobe.com/xap/1.0/rights/">
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
<xmpMM:DocumentID>uuid:E471EDA9-0143-B4EC-2929-27CBFE26697B</xmpMM:DocumentID>
<xmpMM:InstanceID>uuid:33968854-08FD-EA42-AB6D-E80F87295F9F</xmpMM:InstanceID>
<xmpMM:InstanceID>uuid:498FC703-D704-33BB-9C54-7C873CE8022D</xmpMM:InstanceID>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
......
No preview for this file type
No preview for this file type
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