Skip to content

Commit

Permalink
moved towards issue #32
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbates1995 committed May 3, 2023
1 parent c647544 commit e04fd1e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 111 deletions.
Binary file not shown.
52 changes: 17 additions & 35 deletions client/CubePress/Models/Mover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ import Foundation

class Mover {

let conversionTable = ["U": "TMTMBLMC",
"U'": "TMTMBRMC",
"U2": "LTMTMBXCM",
"U2'": "LTMTMBXCM",
"D": "LBXCM",
"R": "LTMBXCM",
"L": "LTMTMTMBXCM",
"F": "TMLBXCM",
"B": "TMTMTMLBXCM"]
let conversionTable = ["U": "TMTM",
"D": "",
"R": "LTMC",
"L": "RTMC",
"F": "TM",
"B": "TMTMTM"]

var referenceFrame = ["U" : "U",
"L" : "L",
"F" : "F",
"R" : "R",
"B" : "B",
"D" : "D",]
"L" : "L",
"F" : "F",
"R" : "R",
"B" : "B",
"D" : "D",]

func input(move: String) {

Expand Down Expand Up @@ -74,24 +71,9 @@ enum MacroMoves: String, CaseIterable, Identifiable, Codable {
case U, D, R, L, F, B
}

let MacroMove: [String: String] = ["U": "LTMTMBXCM",
"U'": "LTMTMBXCM",
"U2": "LTMTMBXCM",
"U2'": "LTMTMBXCM",
"D": "LBXCM",
"R": "LTMBXCM",
"L": "LTMTMTMBXCM",
"F": "TMLBXCM",
"B": "TMTMTMLBXCM"]

let MacroMoveWithReset: [String: String] = ["U": "LTMTMBXCMLTMCTMLTMC",
"U'": "LTMTMBXCMLTMCTMLTMC",
"U2": "LTMTMBXCMLTMCTMLTMC",
"U2'": "LTMTMBXCMLTMCTMLTMC",
"D": "LBXCMLTMCTMRTMC",
"R": "LTMBXCMRTMCTMTMTM",
"L": "LTMTMTMBXCMLTMCTM",
"F": "TMLBXCTMRTMCTMTM",
"B": "TMTMTMLBXCTMRTMC"]


let MacroMove: [String: String] = ["U": "TMTM",
"D": "",
"R": "LTMC",
"L": "RTMC",
"F": "TM",
"B": "TMTMTM"]
32 changes: 18 additions & 14 deletions client/CubePress/Models/Solver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ class Solver {
}

func convert(instruction: String) -> String {
switch (instruction) {
case "B" :
return MacroMove[instruction]!
case "L" :
return MacroMove[instruction]!
case "D" :
return MacroMove[instruction]!
case "F" :
return MacroMove[instruction]!
case "R" :
return MacroMove[instruction]!
case "U" :
return MacroMove[instruction]!
switch instruction.count { //switch on string length
case 1 : //execute standard move
return MacroMove[instruction]! + "BRMC"
case 2 : //determine if prime or double and act accordingly
if instruction.contains("'") { //prime case
return MacroMove[instruction[0]]! + "BLMC"
} else { //double case
return MacroMove[instruction[0]]! + "LBRMC"
}
case 3 : //preform prime double version of move
return MacroMove[instruction[0]]! + "RBLMC"
default:
return "[Conversion Issue]"
return "[error in convert(instruction: UIColor)]"
}
}

Expand Down Expand Up @@ -164,3 +162,9 @@ class Solver {
}
}
}

extension String {
subscript(i: Int) -> String {
return i < count ? String(self[index(startIndex, offsetBy: i)]) : ""
}
}
4 changes: 2 additions & 2 deletions client/CubePress/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct SettingRow: View {

var body: some View {
HStack{
Button("Move \(moveString)") {
Button("Test \(moveString)") {
model.sendSetting(setting: move)
}
Spacer()
Expand All @@ -56,7 +56,7 @@ struct SettingRow: View {
}
}

struct SettingsView_Previews: PreviewProvider {
class SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView(model: .init())
}
Expand Down
40 changes: 10 additions & 30 deletions client/CubePressTests/CubePressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,18 @@ final class CubePressTests: XCTestCase {
testKociembaSolver(map: "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB", expected: "R L U2 R L' B2 U2 R2 F2 L2 D2 L2 F2 ")

//checking each individual conversion
XCTAssertEqual(sut.solver.convert(instructions: "U "), "LTMTMBXCMLTMCTMLTMC")
XCTAssertEqual(sut.solver.convert(instructions: "U' "), "LTMTMBXCMLTMCTMLTMC")
XCTAssertEqual(sut.solver.convert(instructions: "U2 "), "LTMTMBXCMLTMCTMLTMC")
XCTAssertEqual(sut.solver.convert(instructions: "U2' "), "LTMTMBXCMLTMCTMLTMC")

XCTAssertEqual(sut.solver.convert(instructions: "D "), "LBXCMLTMCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "D' "), "LBXCMLTMCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "D2 "), "LBXCMLTMCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "D2' "), "LBXCMLTMCTMRTMC")

XCTAssertEqual(sut.solver.convert(instructions: "R "), "LTMBXCMRTMCTMTMTM")
XCTAssertEqual(sut.solver.convert(instructions: "R' "), "LTMBXCMRTMCTMTMTM")
XCTAssertEqual(sut.solver.convert(instructions: "R2 "), "LTMBXCMRTMCTMTMTM")
XCTAssertEqual(sut.solver.convert(instructions: "R2' "), "LTMBXCMRTMCTMTMTM")

XCTAssertEqual(sut.solver.convert(instructions: "L "), "LTMTMTMBXCMLTMCTM")
XCTAssertEqual(sut.solver.convert(instructions: "L' "), "LTMTMTMBXCMLTMCTM")
XCTAssertEqual(sut.solver.convert(instructions: "L2 "), "LTMTMTMBXCMLTMCTM")
XCTAssertEqual(sut.solver.convert(instructions: "L2' "), "LTMTMTMBXCMLTMCTM")

XCTAssertEqual(sut.solver.convert(instructions: "F "), "TMLBXCTMRTMCTMTM")
XCTAssertEqual(sut.solver.convert(instructions: "F' "), "TMLBXCTMRTMCTMTM")
XCTAssertEqual(sut.solver.convert(instructions: "F2 "), "TMLBXCTMRTMCTMTM")
XCTAssertEqual(sut.solver.convert(instructions: "F2' "), "TMLBXCTMRTMCTMTM")

XCTAssertEqual(sut.solver.convert(instructions: "B "), "TMTMTMLBXCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "B' "), "TMTMTMLBXCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "B2 "), "TMTMTMLBXCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "B2' "), "TMTMTMLBXCTMRTMC")
XCTAssertEqual(sut.solver.convert(instructions: "U "), "TMTMBRMC")
XCTAssertEqual(sut.solver.convert(instructions: "U' "), "TMTMBLMC")
XCTAssertEqual(sut.solver.convert(instructions: "U2 "), "TMTMLBRMC")
XCTAssertEqual(sut.solver.convert(instructions: "U2' "), "TMTMRBLMC")
XCTAssertEqual(sut.solver.convert(instructions: "D "), "BRMC")
XCTAssertEqual(sut.solver.convert(instructions: "R "), "LTMCBRMC")
XCTAssertEqual(sut.solver.convert(instructions: "L "), "RTMCBRMC")
XCTAssertEqual(sut.solver.convert(instructions: "F "), "TMBRMC")
XCTAssertEqual(sut.solver.convert(instructions: "B "), "TMTMTMBRMC")

//checking strings of macroMoves
XCTAssertEqual(sut.solver.convert(instructions: "U D "), "LTMTMBXCMLTMCTMLTMCLBXCMLTMCTMRTMC")
//XCTAssertEqual(sut.solver.convert(instructions: "U D R L F B "), "TMTMLTMCRTMCTMTMTMTM")
}

func testMover() {
Expand Down
60 changes: 30 additions & 30 deletions client/CubePressTests/SolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
import XCTest
@testable import CubePress

class Getter: CubeFaceGetter {
var cubeFace: CubePress.Facelet {
faces.popLast()!
}
var faces: [Facelet]
init(cubeFaces: [Facelet]) {
self.faces = cubeFaces
}
}

class Mover: CubeMovable {
var movesLoged:[Move] = []
func move(to move: CubePress.Move) async {
movesLoged.append(move)
}
}

final class SolverTests: XCTestCase {
func testSolver() async throws {
let getter = Getter(cubeFaces: [Facelet(), Facelet(), Facelet(), Facelet(), Facelet(), Facelet()])
let mover = Mover()
let sut = await Solver(getter: getter, cubeMover: mover, cubeMap: CubeMapModel())
try await sut.scanCube()
//testing that the proper moves were performed
XCTAssertEqual(mover.movesLoged, [CubePress.Move.center, CubePress.Move.mid, CubePress.Move.right, CubePress.Move.left, CubePress.Move.center, CubePress.Move.top, CubePress.Move.mid, CubePress.Move.top, CubePress.Move.mid, CubePress.Move.top, CubePress.Move.mid]) //empty array is supposed to be the expected array
//test that colors are accurate
}
}
//class Getter: CubeFaceGetter {
// var cubeFace: CubePress.Facelet {
// faces.popLast()!
// }
// var faces: [Facelet]
//
// init(cubeFaces: [Facelet]) {
// self.faces = cubeFaces
// }
//}
//
//class Mover: CubeMovable {
// var movesLoged:[Move] = []
//
// func move(to move: CubePress.Move) async {
// movesLoged.append(move)
// }
//}
//
//final class SolverTests: XCTestCase {
// func testSolver() async throws {
// let getter = Getter(cubeFaces: [Facelet(), Facelet(), Facelet(), Facelet(), Facelet(), Facelet()])
// let mover = Mover()
// let sut = await Solver(getter: getter, cubeMover: mover, cubeMap: CubeMapModel())
// try await sut.scanCube()
// //testing that the proper moves were performed
// XCTAssertEqual(mover.movesLoged, [CubePress.Move.center, CubePress.Move.mid, CubePress.Move.right, CubePress.Move.left, CubePress.Move.center, CubePress.Move.top, CubePress.Move.mid, CubePress.Move.top, CubePress.Move.mid, CubePress.Move.top, CubePress.Move.mid]) //empty array is supposed to be the expected array
// //test that colors are accurate
// }
//}

0 comments on commit e04fd1e

Please sign in to comment.