using DataFrames
import CSV
using StatsBase
using PrettyTablesRoshambo Rock, Paper, Scissors Reference
include("CommonFunctions.jl")
include("RPS.jl")
include("Constants.jl")Dict{String, String} with 4 entries:
"Guessing the Paintings" => "painting"
"Time" => "time"
"Rock, Paper, Scissors" => "rps"
"DC-5 Lottery" => "lottery"
data = createdata(joinpath("..", "Data", "OriginalData", "Rock_Paper_Scissors_Raw_data.csv"), 5)
roshambo = fillstrat(data, 5);size(roshambo)(5, 44422)
proportionmap(roshambo[1, :])Dict{Int64, Float64} with 3 entries:
2 => 0.356062
3 => 0.290779
1 => 0.353158
RPSbyrounds = DataFrame()
for i = 1:5
res = DataFrame()
p = proportionmap(roshambo[i, :])
for (k, v) = p
res[!, "$k"] = [v]
end
append!(RPSbyrounds, res)
end
rename!(RPSbyrounds, "1" => :Rock, "2" => :Paper, "3" => :Scissors)
RPSbyrounds5×3 DataFrame
| Row | Paper | Scissors | Rock |
|---|---|---|---|
| Float64 | Float64 | Float64 | |
| 1 | 0.356062 | 0.290779 | 0.353158 |
| 2 | 0.334519 | 0.327135 | 0.338346 |
| 3 | 0.336635 | 0.318153 | 0.345212 |
| 4 | 0.32718 | 0.323353 | 0.349466 |
| 5 | 0.342916 | 0.315227 | 0.341858 |
confrpsroshambo = set_pt_conf(
title = "RPS strategies played by the Roshambo sample.",
row_labels = ["Round $i" for i=1:5],
row_label_alignment = :l,
alignment = :c,
header=["Paper", "Scissors", "Rock"],
row_label_column_title = "",
formatters = (percent_format(2)),
)
pretty_table_with_conf(confrpsroshambo, RPSbyrounds)RPS strategies played by the Roshambo sample.
┌─────────┬────────┬──────────┬────────┐
│ │ Paper │ Scissors │ Rock │
├─────────┼────────┼──────────┼────────┤
│ Round 1 │ 35.61% │ 29.08% │ 35.32% │
│ Round 2 │ 33.45% │ 32.71% │ 33.83% │
│ Round 3 │ 33.66% │ 31.82% │ 34.52% │
│ Round 4 │ 32.72% │ 32.34% │ 34.95% │
│ Round 5 │ 34.29% │ 31.52% │ 34.19% │
└─────────┴────────┴──────────┴────────┘
open(joinpath("..", "Data", "Output", "TableRPSRoshambo.tex"), "w") do f
pretty_table_with_conf(confrpsroshambo, f, RPSbyrounds, backend = Val(:latex), tf = tf_latex_modern)
endComputing the Best Strategy
universe = ones(Int, 5, 3^5)
c = 0
for i = 1:3, j = 1:3, k = 1:3,l = 1:3, m = 1:3
c += 1
universe[:, c] = [i, j, k, l, m]
endbeststrategy = session(universe, roshambo)
beststrategy[!, :index] = collect(1:3^5);bestindex = beststrategy[beststrategy[!, :SD] .== maximum(beststrategy[!, :SD]), :index]
println("Best strategy: ", (x -> translate(x, RPS_inv)).(universe[:, bestindex]))
println("its probability of winning is ", round(maximum(beststrategy[!, :SD]), digits = 4))
worstindex = beststrategy[beststrategy[!, :SD] .== minimum(beststrategy[!, :SD]), :index]
println("Worst strategy: ",(x -> translate(x, RPS_inv)).(universe[:, worstindex]))
println("its probability of winning is ", round(minimum(beststrategy[!, :SD]), digits = 4))Best strategy: ["Paper"; "Paper"; "Paper"; "Paper"; "Paper";;]
its probability of winning is 0.5379
Worst strategy: ["Rock"; "Rock"; "Scissors"; "Scissors"; "Rock";;]
its probability of winning is 0.463