Skip to content

Commit

Permalink
Added a worm chart type. Required storing some extra progress info du…
Browse files Browse the repository at this point in the history
…ring the game
  • Loading branch information
JerBoon committed Sep 30, 2019
1 parent 54398c4 commit 0ad5ad2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
.DS_Store
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
.DS_Store
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: yahtzR
Type: Package
Title: Play variations of the well-known dice rolling game in an R session
Version: 1.3.3
Version: 1.3.4
Author: Jer Boon
Maintainer: Jer Boon <[email protected]>
Description:
Expand Down
6 changes: 6 additions & 0 deletions R/make_choice.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ make_choice <- function(game, work.mode=F) {
supply_more_info <- T
if(!work.mode)
cat("Select which option to score using the 2 letter code. Valid entries are:\n")
} else if (input == "test") {
print(game$table)
} else if (input %in% sections.available) {
print(paste("you chose",input))
table[table$section == input, "score"] <- table[table$section == input, "score.available"]
Expand All @@ -81,6 +83,10 @@ make_choice <- function(game, work.mode=F) {
table[table$section=="lt", "score"] <- sum(table[table$half == 2,"score"],na.rm=T)
table[table$section=="gt", "score"] <- sum(table[table$half %in% c(1,2),"score"],na.rm=T)

#update running total and choice order info
table[table$section == input, "score.running"] <- table[table$section=="gt", "score"]
table[table$section == input, "score.sequence"] <- sum(!is.na(table$score.running))

game$table <- table
game$dice <- NA

Expand Down
22 changes: 20 additions & 2 deletions R/plot_card.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plot_card <- function(game, work.mode) {
random_colour <- sample(c("red","green","orange","blue","black","grey"),1)

# Print a random chart
style <- sample(1:5,1)
style <- sample(1:7,1)

# ------------------------

Expand Down Expand Up @@ -110,6 +110,25 @@ plot_card <- function(game, work.mode) {
ggplot2::scale_x_discrete(name="") +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle=90, hjust=1, vjust=0.5))

}
else if (style %in% c(6,7))
{
#Progress worm - inspired by watching cricket! :)

gg <-
ggplot2::ggplot(gg.dat[!is.na(gg.dat$score.sequence),],
ggplot2::aes(x=factor(score.sequence),y=score.running)) +
base_theme +
ggplot2::scale_fill_brewer(palette = base_palette) +
ggplot2::geom_line(ggplot2::aes(group="1"),size=1.5,alpha=0.7,color=random_colour) +
ggplot2::geom_point(size=3,color=random_colour) +
ggplot2::geom_text(ggplot2::aes(label=label),hjust=-0.2, angle=-15) +
ggplot2::scale_y_continuous(limits=c(0,max(gg.dat$score.running))) +
ggplot2::scale_x_discrete(expand=ggplot2::expand_scale(add=1)) +
ggplot2::ylab("Cumulative total") +
ggplot2::xlab("Turn") +
ggplot2::theme(legend.position = "none")

}

# Standard titles
Expand All @@ -121,5 +140,4 @@ plot_card <- function(game, work.mode) {
subtitle = paste("Total score = ",game$table[game$table$section == "gt", "score"]))

suppressWarnings(print(gg))

}

0 comments on commit 0ad5ad2

Please sign in to comment.