TEST: Get a List of overlapping moves

This commit is contained in:
Aldin Duraki 2020-05-15 20:45:52 +02:00
parent 4cf9b8c95e
commit 009b39ca14
2 changed files with 10 additions and 6 deletions

View File

@ -48,10 +48,10 @@ class TimerComponent: GKComponent {
if !MultiplayerNetwork.sharedInstance.isSending {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
}
if DataService.sharedInstance.didReceiveAllData() {
if !RoundCalculatorServie.sharedInstance.isCalculating
&& DataService.sharedInstance.didReceiveAllData(){
RoundCalculatorServie.sharedInstance.calculateRound()
}
}
}

View File

@ -13,24 +13,28 @@ import os
class RoundCalculatorServie {
static let sharedInstance = RoundCalculatorServie()
var allPlayerMoves: [String: [PlayerMove]] = [:]
var baseSpecificMove: [Int: [(String, PlayerMove)]] = [:]
var isCalculating = false
func calculateRound() {
isCalculating = true
for entry in DataService.sharedInstance.remotePlayerMoves {
addPlayerMove(playerID: entry.key, playerMoves: entry.value)
}
addPlayerMove(playerID: GKLocalPlayer.local.displayName, playerMoves: DataService.sharedInstance.localPlayerMoves)
// berechnen nach minimal substraction
for entry in allPlayerMoves {
for move in entry.value {
addFiltedMove(playerName: entry.key, playerMove: move)
}
}
// berechnen nach minimal substraction
print(baseSpecificMove)
isCalculating = false
// sende an alle anderen spieler die moves
}
@ -39,6 +43,6 @@ class RoundCalculatorServie {
}
func addFiltedMove(playerName: String, playerMove: PlayerMove) {
self.baseSpecificMove[playerMove.toBase]!.append((playerName, playerMove))
self.baseSpecificMove.merge([playerMove.toBase : [(playerName, playerMove)]], uniquingKeysWith: +)
}
}