コード例 #1
0
game = RockPaperScissors()

resultFile = open("output.txt", 'w', 0)
resultWriter = csv.writer(resultFile)
resultWriter.writerow(["prediction","actual"])
resultWriter.writerow(["int","int"])
resultWriter.writerow(["",""])

predictionQueue = Queue(maxsize=predictionSteps + 2)
for i in range(predictionSteps):
	predictionQueue.put(-1)

count = 0
while count < SIM_COUNT:
	player1 = int(random.random() * 3)
	player2 = int(random.random() * 3)
	scoreBeforeDuel = game.score
	result = model.run({
		"player1": player1,
		"player2": player2,
		"scoreBeforeDuel": scoreBeforeDuel
	})
	futurePrediction = result.inferences["multiStepBestPredictions"][predictionSteps]
	predictionQueue.put(futurePrediction)
	prediction = predictionQueue.get()
	resultWriter.writerow([prediction, game.score])
	game.processRound(player1, player2)
	if count % 100 == 0:
		print "count: " + str(count)
	count += 1
コード例 #2
0
model.enableInference({'predictedField': 'winner'})

game = RockPaperScissors()

resultFile = open("output.txt", 'w', 0)
resultWriter = csv.writer(resultFile)
resultWriter.writerow(["prediction","actual","correct"])
resultWriter.writerow(["string","string","string"])
resultWriter.writerow(["","",""])

count = 0
lastWinner = "draw"
while count < SIM_COUNT:
	player1 = int(random.random() * 3)
	player2 = int(random.random() * 3)
	winner = game.processRound(player1, player2)
	row = {
		"player1": game.roles[player1],
		"player2": game.roles[player2],
		"winner": lastWinner
	}
	result = model.run(row)
	futurePrediction = result.inferences["multiStepBestPredictions"][predictionSteps]
	correct = futurePrediction == winner

	# print "{0} {1}: winner: {2}".format(game.roles[player1], game.roles[player2], futurePrediction)
	resultWriter.writerow([futurePrediction, winner, correct])
	
	lastWinner = winner
	if count % 100 == 0:
		print "count: " + str(count)