Beispiel #1
0
// add adds a mancala.Result into the data aggregated by the Result.
func (result *Result) add(gameResult mancala.Result) {
	result.N++
	moveCount := gameResult.MoveCount()
	if result.AvgMoveCount == -1 {
		result.AvgMoveCount = 0
	}
	result.AvgMoveCount = nextAverage(
		result.AvgMoveCount,
		result.N,
		moveCount,
	)
	if result.MinMoveCount == -1 {
		result.MinMoveCount = moveCount
	} else if moveCount < result.MinMoveCount {
		result.MinMoveCount = moveCount
	}
	if result.MaxMoveCount == -1 {
		result.MaxMoveCount = moveCount
	} else if moveCount > result.MaxMoveCount {
		result.MaxMoveCount = moveCount
	}
	if gameResult.Winner() == -1 {
		result.TieCount++
		if result.AvgMoveCountWithTie == -1 {
			result.AvgMoveCountWithTie = 0
		}
		result.AvgMoveCountWithTie = nextAverage(
			result.AvgMoveCountWithTie,
			result.TieCount,
			moveCount,
		)
		if result.MinMoveCountWithTie == -1 {
			result.MinMoveCountWithTie = moveCount
		} else if moveCount < result.MinMoveCountWithTie {
			result.MinMoveCountWithTie = moveCount
		}
		if result.MaxMoveCountWithTie == -1 {
			result.MaxMoveCountWithTie = moveCount
		} else if moveCount > result.MaxMoveCountWithTie {
			result.MaxMoveCountWithTie = moveCount
		}
	}
	result.Player1.add(gameResult)
	result.Player2.add(gameResult)
	if gameResult.Err() != nil {
		result.Errs = append(result.Errs, gameResult.Err().Error())
	}
}
Beispiel #2
0
// add adds a mancala.Result into the data aggregated by the PlayerResult.
func (result *PlayerResult) add(gameResult mancala.Result) {
	result.n++
	moveCount := gameResult.MoveCount()
	seedCount := gameResult.Board().ScoreFor(result.index)
	if result.AvgSeedCount == -1 {
		result.AvgSeedCount = 0
	}
	result.AvgSeedCount = nextAverage(
		result.AvgSeedCount,
		result.n-1,
		seedCount,
	)
	if result.MinSeedCount == -1 {
		result.MinSeedCount = seedCount
	} else if seedCount < result.MinSeedCount {
		result.MinSeedCount = seedCount
	}
	if result.MaxSeedCount == -1 {
		result.MaxSeedCount = seedCount
	} else if seedCount > result.MaxSeedCount {
		result.MaxSeedCount = seedCount
	}
	if gameResult.Winner() == result.index {
		if result.AvgMoveCountWithWin == -1 {
			result.AvgMoveCountWithWin = 0
		}
		result.WinCount++
		result.AvgMoveCountWithWin = nextAverage(
			result.AvgMoveCountWithWin,
			result.WinCount-1,
			moveCount,
		)
		if result.AvgSeedCountWithWin == -1 {
			result.AvgSeedCountWithWin = 0
		}
		result.AvgSeedCountWithWin = nextAverage(
			result.AvgSeedCountWithWin,
			result.WinCount-1,
			seedCount,
		)
		if result.MinMoveCountWithWin == -1 {
			result.MinMoveCountWithWin = moveCount
		} else if moveCount < result.MinMoveCountWithWin {
			result.MinMoveCountWithWin = moveCount
		}
		if result.MaxMoveCountWithWin == -1 {
			result.MaxMoveCountWithWin = moveCount
		} else if moveCount > result.MaxMoveCountWithWin {
			result.MaxMoveCountWithWin = moveCount
		}
	} else if gameResult.Winner() != -1 {
		result.LossCount++
		if result.AvgMoveCountWithLoss == -1 {
			result.AvgMoveCountWithLoss = 0
		}
		result.AvgMoveCountWithLoss = nextAverage(
			result.AvgMoveCountWithLoss,
			result.LossCount-1,
			moveCount,
		)
		if result.AvgSeedCountWithLoss == -1 {
			result.AvgSeedCountWithLoss = 0
		}
		result.AvgSeedCountWithLoss = nextAverage(
			result.AvgSeedCountWithLoss,
			result.LossCount-1,
			seedCount,
		)
		if result.MinMoveCountWithLoss == -1 {
			result.MinMoveCountWithLoss = moveCount
		} else if moveCount < result.MinMoveCountWithLoss {
			result.MinMoveCountWithLoss = moveCount
		}
		if result.MaxMoveCountWithLoss == -1 {
			result.MaxMoveCountWithLoss = moveCount
		} else if moveCount > result.MaxMoveCountWithLoss {
			result.MaxMoveCountWithLoss = moveCount
		}
	}
}