-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated simulation, summary, and plot functions. Changed vignette. Up…
…dated manuals and descriptions.
- Loading branch information
Showing
12 changed files
with
128 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
Package: partyGames | ||
Type: Package | ||
Title: Tool to Simulate Various Party Games and Develop Better Strategies | ||
Title: Simulate Party Games | ||
Version: 0.1.0 | ||
Author: Kline DuBose | ||
Maintainer: Kline DuBose <[email protected]> | ||
Description: Simulation tools that help develop better strategies to win at party games. | ||
Description: Simulation tools that allow users to play party games and simulate | ||
multiple games at a time to improve strategies. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
|
@@ -16,5 +17,8 @@ RoxygenNote: 7.2.3 | |
LinkingTo: | ||
Rcpp | ||
Imports: | ||
Rcpp | ||
Rcpp, | ||
methods, | ||
parallel, | ||
graphics | ||
VignetteBuilder: knitr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#' @importFrom Rcpp evalCpp | ||
#' @importFrom parallel makeCluster parSapply stopCluster | ||
#' @importFrom graphics barplot | ||
#' @importFrom methods is | ||
#' @useDynLib partyGames, .registration = TRUE | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' Plot results of a White Elephant simulation | ||
#' | ||
#' A general function to plot the results of a White Elephant simulation. | ||
#' | ||
#' @param sim An object of class `elphList` or `elphSum` to be summarized | ||
#' @param ... Arguments to be passed to other methods. See `barplot` for further details. | ||
#' | ||
#' @return A plot showing the distribution of each winning seat and how often they won. | ||
#' | ||
#' @export | ||
#' | ||
#' | ||
|
||
|
||
plotElephant <- function(sim, ...){ | ||
if(!(is(sim, "elphList") | is(sim, "elphSum"))) stop("'sim' must be an 'elphList' or 'elphSum' class object") | ||
|
||
if(is(sim, "elphList")){ | ||
sim <- summaryElephant(sim) | ||
} | ||
|
||
|
||
barplot( | ||
sim[[1]] / sum(sim[[1]]), | ||
ylim = c(0, max(sim[[1]] / sum(sim[[1]])) + 0.05), | ||
sub = sprintf("Distribution of %i simulated white elephant games", sum(sim[[1]])), | ||
main = "Who gets the present?", | ||
col = "cornflowerblue", | ||
border = "dimgray" | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' Summarize a simulation | ||
#' | ||
#' A general function to summarize a simulation of white elephant games. | ||
#' | ||
#' @param sim An object of class `elphList` to be summarized | ||
#' | ||
#' @return An object of class `elphSum` containing a table of moves over a | ||
#' simulation and a table of times each chair won. | ||
#' | ||
#' @export | ||
#' | ||
#' | ||
|
||
summaryElephant <- function(sim){ | ||
if (!is(sim, "elphList")) stop("sim must be a 'elphList' class object") | ||
|
||
moves <- sapply(sim, "[[", "moves") | ||
|
||
moves <- table(moves) | ||
|
||
winner <- sapply(sim, "[[", "winner") | ||
|
||
winner <- table(winner) | ||
|
||
elphSum <- list(winner = winner, moves = moves) | ||
|
||
class(elphSum) <- c("elphSum", "list") | ||
|
||
return(elphSum) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ expect_equal( | |
set.seed(123) | ||
ans3 <- leftRightElephant(10, 0.5) | ||
expect_equal( | ||
9, | ||
1, | ||
ans3[[2]] | ||
) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters