Title: | Create shiny apps to play gtree games |
---|---|
Description: | Create shiny web apps that allow single users to play game-theoretic gtree games against the computer who can e.g. follow equilibrium strategies, or average behavior of the population of all players so far. |
Authors: | Sebastian Kranz |
Maintainer: | Sebastian Kranz <[email protected]> |
License: | GPL >= 2.0 |
Version: | 0.0.1 |
Built: | 2024-11-29 02:52:43 UTC |
Source: | https://github.com/skranz/gtreeWebPlay |
Bot that plays according to a specified equilibrium
bot_eq(game, player, eq = game$eq.li[[1]], eq.tables = gtree::eq_tables(game = game, eq.li = list(eq)), name = "eq_bot", ...)
bot_eq(game, player, eq = game$eq.li[[1]], eq.tables = gtree::eq_tables(game = game, eq.li = list(eq)), name = "eq_bot", ...)
game |
the game object |
player |
the player number of this bot |
eq |
an equilibrium, typically an element of game$eq.li |
Other Bots: bot_mixture
,
bot_pop
, bot_random
,
bot_tables
, make_bots
,
play_bot_vs_bot
The first time the bot is called for a particular player in a play He picks a child bot randomly. Then it continues with that child bot for this player the whole play.
bot_mixture(game, player, child_bots, prob = NULL, ...)
bot_mixture(game, player, child_bots, prob = NULL, ...)
game |
the game object |
player |
the player number of this bot |
child_bots |
A list of child pots |
prob |
A vector of weights for each child bot. If |
If you use make_bots
or call
repeatedly bot_mixture
to generate mixture bots
for each player, the child bots will be independently
drawn for each player.
Instead, if bot1 is a mixture bot for player 1
and you create a mixture bot for player 2 by
bot2 = bot1\nbot2$player = 2
then bot2 will select in every play the same
child bot than bot1.
Other Bots: bot_eq
, bot_pop
,
bot_random
, bot_tables
,
make_bots
, play_bot_vs_bot
Draws actions from previous actions stored in population play summary (pps) object
bot_pop(game, player, pps, alt.bot = NULL, alt.bot.count = 5, name = "pop_bot", alt.bot.fun = bot_random, ...)
bot_pop(game, player, pps, alt.bot = NULL, alt.bot.count = 5, name = "pop_bot", alt.bot.fun = bot_random, ...)
game |
the game object |
player |
the player number of this bot |
pps |
a pps object, can be extended during play. |
alt.bot |
a bot who will be aksed if there are too few observations in the popoulation |
alt.bot.count |
we assume that we already have this many observations for alt.bot. This determines the probability to draw from the alt.bot instead of the population |
Other Bots: bot_eq
,
bot_mixture
, bot_random
,
bot_tables
, make_bots
,
play_bot_vs_bot
Other population play functions: new_pps
,
pps_add_play_actions
,
pps_rearrange
Always picks each possible move with equal probability
bot_random(game, player, ...)
bot_random(game, player, ...)
game |
the game object |
player |
the player number of this bot |
Other Bots: bot_eq
,
bot_mixture
, bot_pop
,
bot_tables
, make_bots
,
play_bot_vs_bot
Bot whose actions are determined by key-action tables
bot_tables(game, player, tables, name = "table_bot", ...)
bot_tables(game, player, tables, name = "table_bot", ...)
game |
the game object |
player |
the player number of this bot |
tables |
a list of tables for each action. The result of |
Other Bots: bot_eq
,
bot_mixture
, bot_pop
,
bot_random
, make_bots
,
play_bot_vs_bot
Deploys an example app to local directory
deploy_webplay_example(example = c("UltimatumGame", "KuhnPoker")[1], dest.dir = file.path(getwd(), example))
deploy_webplay_example(example = c("UltimatumGame", "KuhnPoker")[1], dest.dir = file.path(getwd(), example))
example |
Name of the example. Current options are \n\t1. |
dest.dir |
The destination directory |
Gets the web play object of the current app instance
get_wp(app = getApp())
get_wp(app = getApp())
set_wp_for_app
Other Web Play: new_wp
,
set_wp_for_app
, wpDevelApp
,
wp_copy
, wp_developer_ui
,
wp_reset
, wp_set_to_play
Every player gets the same bot type
make_bots(game, bot_fun, ..., players = game$players)
make_bots(game, bot_fun, ..., players = game$players)
game |
the game object |
bot_fun |
a bot function like e.g. |
... |
additional arguments passed to |
Other Bots: bot_eq
,
bot_mixture
, bot_pop
,
bot_random
, bot_tables
,
play_bot_vs_bot
Create a new empty population play summary
new_pps(...)
new_pps(...)
Other population play functions: bot_pop
,
pps_add_play_actions
,
pps_rearrange
Create a new web play object
new_wp(game, bots, human = draw_human_pos(human_draw_method = human_draw_method, numPlayers = game$vg$params$numPlayers, human = 0), human_draw_method = c("cycle", "random", "fixed")[1], wpUI = "wpUI", verbose = FALSE, pages.dir = file.path(getwd(), "pages"), custom = list(), pre.page.handler = NULL, post.page.handler = NULL, finish.handler = wp.default.finish.handler, comp.pages = as.environment(list()), page.ui.fun = NULL, ...)
new_wp(game, bots, human = draw_human_pos(human_draw_method = human_draw_method, numPlayers = game$vg$params$numPlayers, human = 0), human_draw_method = c("cycle", "random", "fixed")[1], wpUI = "wpUI", verbose = FALSE, pages.dir = file.path(getwd(), "pages"), custom = list(), pre.page.handler = NULL, post.page.handler = NULL, finish.handler = wp.default.finish.handler, comp.pages = as.environment(list()), page.ui.fun = NULL, ...)
game |
A gtree game generated with |
bots |
A list with one bots for every player. Also add a bot for the human player. You can call |
human |
index of the player that is played by a human in the first play of the web app. |
human_draw_method |
Method how the index of the human player is determined by default if a new play is started. The default |
wpUI |
the id of the |
verbose |
shall information about state of play be printed to the standard output? |
pages.dir |
the directory in which the Rmd files for the stage pages can be found. By default |
custom |
A list of custom parameters that will be passed to handlers. |
pre.page.handler |
a function that is called before a page is shown to a human. It should return a list of values that can be accessed in the whiskers of the page Rmd file. |
post.page.handler |
a function that is called after a human made input in a stage. Can for example be used to update a population play summary. (See the KuhnPoker example) |
finish.handler |
is called when the final results page of a play is left. The default handler simply starts a new play. |
page.ui.fun |
optionally a function that returns for each page a shiny tag that will be shown. If NULL (default) we specify the page ui via Rmd files in the pages subfolder. |
Other Web Play: get_wp
,
set_wp_for_app
, wpDevelApp
,
wp_copy
, wp_developer_ui
,
wp_reset
, wp_set_to_play
Simulate one play of the game
play_bot_vs_bot(game, bots, return.play.object = FALSE)
play_bot_vs_bot(game, bots, return.play.object = FALSE)
game |
the game object |
bots |
a list containing one bot per player |
return.play.object |
By default only the outcome of the play as a one-row data frame is returned. If you set |
Other Bots: bot_eq
,
bot_mixture
, bot_pop
,
bot_random
, bot_tables
,
make_bots
Call this function in the post.page.handler to update the population play summary
pps_add_play_actions(pps, play, stage.num = play$human.stage.finished)
pps_add_play_actions(pps, play, stage.num = play$human.stage.finished)
Other population play functions: bot_pop
,
new_pps
, pps_rearrange
If the pps is dynamically created during plays the column order may change
pps_rearrange(pps)
pps_rearrange(pps)
Other population play functions: bot_pop
,
new_pps
, pps_add_play_actions
Assigns a copy of a global web play object to the current instance of the shiny app. This means every user has her own instance. Note that it is not possible to have two or more web plays active in the same app.
set_wp_for_app(wp, app = getApp(), copy = TRUE)
set_wp_for_app(wp, app = getApp(), copy = TRUE)
The function get_wp() returns the web play object of the current app instance.
Other Web Play: get_wp
, new_wp
,
wpDevelApp
, wp_copy
,
wp_developer_ui
, wp_reset
,
wp_set_to_play
Copy a web play object
wp_copy(wp)
wp_copy(wp)
Other Web Play: get_wp
, new_wp
,
set_wp_for_app
, wpDevelApp
,
wp_developer_ui
, wp_reset
,
wp_set_to_play
Returns a shiny tag list that you can add to your app$ui definition. It contains buttons to restart the experiment, edit the page rmd file in RStudio and to refresh an edited page. Button handlers are automatically added.
wp_developer_ui()
wp_developer_ui()
Other Web Play: get_wp
, new_wp
,
set_wp_for_app
, wpDevelApp
,
wp_copy
, wp_reset
,
wp_set_to_play
If you immediately want to start the new play. Call
wp_continue
afterwards.
wp_reset(wp = get_wp(), bots = wp$play$bots, human = draw_human_pos(wp))
wp_reset(wp = get_wp(), bots = wp$play$bots, human = draw_human_pos(wp))
wp |
A web play object |
bots |
You can provide new bots. By default the current bots are used again. |
human |
You can define a new index of the human player. By default the current human is used. |
Other Web Play: get_wp
, new_wp
,
set_wp_for_app
, wpDevelApp
,
wp_copy
, wp_developer_ui
,
wp_set_to_play
Can for example be used to continue with a human after bots played some earlier rounds
wp_set_to_play(wp, play, human = play$human)
wp_set_to_play(wp, play, human = play$human)
Other Web Play: get_wp
, new_wp
,
set_wp_for_app
, wpDevelApp
,
wp_copy
, wp_developer_ui
,
wp_reset
Returns a shinyEvents app. You can view the app in RStudio using [shinyEvents]viewApp
wpDevelApp(wp, title = paste0("Playing ", wp$play$game$gameId))
wpDevelApp(wp, title = paste0("Playing ", wp$play$game$gameId))
wp |
a web play object generated with |
title |
A title string |
Other Web Play: get_wp
, new_wp
,
set_wp_for_app
, wp_copy
,
wp_developer_ui
, wp_reset
,
wp_set_to_play