TEST: Get a List of overlapping moves
This commit is contained in:
parent
4cf9b8c95e
commit
009b39ca14
@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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: +)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user