tomaztsql posted: " Playing a simple guessing game with R. It's called Mastermind game! This game was originally created for two people, but R version will be for single-player mode, when an R developer or R data scientists need a break. The gameplay is simple and so are" Playing a simple guessing game with R. It's called Mastermind game! This game was originally created for two people, but R version will be for single-player mode, when an R developer or R data scientists need a break. The gameplay is simple and so are the rules. The board contains 10 rows (or more) with possibilities of four colours and code pegs (white or black). R engine stores a secret colour combination and user selects a random combination. Based on selection, the R engine returns the black or white pegs. Black peg represents that one colour is at the right place, white that the colour matches, but not the position. No pegs would mean that none of selected colours matches the secret colour combination. Using x11() function, this game becomes so much fun with R. And the outlooks is: The game code consists of board function, adding colours on the board, checking for the code pegs function and gameplay function. ########################################## # # Mastermind board game for R Language # # Game for single-player R developers/Data scientists for # killing time, playing game while waiting for the ML # model to finish training or just to play. # # Series: # Little Useless-useful R functions #31 # Created: January 06, 2022 # Author: Tomaz Kastrun # Blog: tomaztsql.wordpress.com # V.1.0 # Changelog: ########################################### numberOfColors <- 4 numberOfTries <- 10 get_board <- function(nof_col, nof_try=10){ plot.new() op <- par(bg = "white") grid(nx = 6, ny = 12, col = "gray", lty = "dotted",lwd = par("lwd"), equilogs = TRUE) # adding boarders par(new = TRUE) plot(c(100,500), c(100,500), xlab = "", ylab = "", xaxt = 'n', yaxt = 'n',main = "Mastermind board game") nof_tries <- nof_try for (i in 1:nof_tries) { #rows for (j in 1:nof_col) { #columns col <- 50*(1:nof_col-1) rect(100+col[j], 500-(i*30), 150+col[j], 475-(i*30), col = 'white') } } colours = c('Red','Green','Blue','Yellow','Brown','Orange') for (z in 1:nof_col) { rect(100+z*50, 100, 150+z*50, 150, col = colours[z]) } } add_rect <- function(colour,try,nof_try=10) { par(new = TRUE) max_tries <- numberOfColors*nof_try #10 rows if (try %% numberOfColors == 0) { #number of tries = number of colours nof_try <- try/numberOfColors add_key_pegs(input_colours,store_secret, nof_try) } if (try > numberOfColors){ row <- ceiling((try/numberOfColors)) rect_order <- abs(try-((row-1)*numberOfColors)) } else { row <- 1 rect_order <- try } rect(100+(rect_order*50)-50, 500-(row*30),150+((rect_order*50))-50, 475-(row*30), col = colour) } add_key_pegs <- function(input_colours, store_secret,nof_try){ ss <- store_secret ic <- input_colours ss1 <- as.vector(strsplit(as.character(ss), "")[[1]]) ic1 <- as.vector(strsplit(as.character(ic), "")[[1]]) white <- "" black <- "" for (i in 1:length(ss1)){ for (j in 1:length(ic1)){ if (i==j && ss1[i] == ic1[j]) {black <- as.integer(paste( c(black, ic1[j]),collapse=""))} if (ss1[i] == ic1[j]) { white <- as.integer(paste( c(white, ic1[j]),collapse="")) } } } black1 <- as.vector(strsplit(as.character(black), "")[[1]]) white1 <- as.vector(strsplit(as.character(white), "")[[1]]) black <- nchar(black) white <- length(unique(setdiff(white1, black1))) nof_tokes <- black + white tok <- replicate(black, "black") en <- replicate(white, "gray") token <- c(tok, en) name1 <- token[1] name2 <- token[2] name3 <- token[3] name4 <- token[4] if (nof_tokes == 1) { par(new = TRUE) plot(450,500-(nof_try*30), col = name1, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) } if (nof_tokes == 2) { par(new = TRUE) plot(450,500-(nof_try*30), col = name1, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) par(new = TRUE) plot(450,490-(nof_try*30), col = name2, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) } if (nof_tokes == 3) { par(new = TRUE) plot(450,500-(nof_try*30), col = name1, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) par(new = TRUE) plot(450,490-(nof_try*30), col = name2, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) par(new = TRUE) plot(470,500-(nof_try*30), col = name3, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) } if (nof_tokes == 4) { par(new = TRUE) plot(450,500-(nof_try*30), col = name1, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) par(new = TRUE) plot(450,490-(nof_try*30), col = name2, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) par(new = TRUE) plot(470,500-(nof_try*30), col = name3, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) par(new = TRUE) plot(470,490-(nof_try*30), col = name4, lwd = 2, xaxt = 'n', yaxt = 'n', xlab = "",ylab = "",xlim=range(100:500), ylim=range(100:500)) } } get_secret <- function(nof_col, colours_repeat=FALSE) { colours <- c(1:4) s <- sample(colours,nof_col, replace=colours_repeat) s <- paste(s, collapse="") return(as.integer(s)) } game <- function(numberOfColors=4, numberOfTries=10){ rm(list = ls()) x11() end_game <- 1 count <<- 0 get_board(nof_col = numberOfColors, nof_try = numberOfTries) store_secret <<- get_secret(nof_col=numberOfColors, colours_repeat =TRUE) input_colours <<- 0L #input_colours <- c("Blue", "Yellow","Green","Yellow") #, "Brown", "Green") nof_selection <- numberOfColors max_tries <- nof_selection*numberOfTries while (end_game <= max_tries && store_secret != input_colours) { mouse.at <- locator(n = 1, type = "o") x.at <- mouse.at$x y.at <- mouse.at$y if (x.at >= 150 & x.at < 200 & y.at >= 100 & y.at <=150) { input_colours <<- as.integer(paste( c(input_colours, 1),collapse="")) add_rect('Red',end_game) } if (x.at >= 200 & x.at < 250 & y.at >= 100 & y.at <=150) { input_colours <<- as.integer(paste( c(input_colours, 2),collapse="")) add_rect('Green',end_game) } if (x.at >= 250 & x.at < 300 & y.at >= 100 & y.at <=150) { input_colours <<- as.integer(paste( c(input_colours, 3),collapse="")) add_rect('Blue',end_game) } if (x.at >= 300 & x.at < 350 & y.at >= 100 & y.at <=150) { input_colours <<- as.integer(paste( c(input_colours, 4),collapse="")) add_rect('Yellow',end_game) }
Mayank Verma posted: " While working on a code we intend to make it functional. But it is equally important that we make sure our code works the way we intended it to. And we can achieve that by witting unit test cases. In this blog, we will cover the same by considering two t" While working on a code we intend to make it functional. But it is equally important that we make sure our code works the way we intended it to. And we can achieve that by witting unit test cases. In this blog, we will cover the same by considering two testing scenarios. First, where the […] Read more of this post |
|
|
|
|
admin posted: " Float has a size of 32 bits, a minimum value of 1.4E-45 and a maximum value of 3.4028235E38.Double has a size of 64 bits, a minimum value of 4.9E-324 and a maximum value of 1.7976931348623157E308. " Float has a size of 32 bits, a minimum value of 1.4E-45 and a maximum value of 3.4028235E38. Double has a size of 64 bits, a minimum value of 4.9E-324 and a maximum value of 1.7976931348623157E308. |
|
|
|
|
Lord Voldemort posted: " Learn and Master Selenium 4.0 latest features, Chrome DevTools Protocol, Grid 4, Docker, AWS Integration & CI/CD Jenkins What you'll learn All latest features of Selenium 4.0 Migrating from Selenium 3 to 4.0 Ma" Learn and Master Selenium 4.0 latest features, Chrome DevTools Protocol, Grid 4, Docker, AWS Integration & CI/CD Jenkins What you'll learn All latest features of Selenium 4.0 Migrating from Selenium 3 to 4.0 Many new updates and enhancement from Selenium 3 Relative Locators, Chrome DevTools Protocols, New Window and Tabs handling, Elements and Full page […] Read more of this post |
|
|
|
|
Start New Year with new arrival coffes 🤗 Let's check them out! Photo credit to Mei Tyin Start New Year with New Arrival Coffees! Here are a couple of vibrant coffees that you have to check them out let's go 😎 | | Ethiopia Bombe Calling all dark roast coffee fans, this is the one for you. Brew & Bread takes on a natural Ethiopian coffee to give uniqueness to showcase the flavours! Full bodied cuppa with all the classic fruity notes of strawberry, raspberry & blueberry. Enjoy this coffee in the morning & you'll have a great day 🤩 | | Costa Rica Hacienda Copey This natural coffee a super fruity punch! Packed with fruity notes of apple & red cherry, pair with a lovely orange candy sweetness. A delightful coffee to enjoy in the morning to kickstart your day 🤩 | | Nicaragua Jinotega Caturra VWI by CHADWANG loves smooth coffee with lovely sweetness. This natural Caturra is no exception! You'll get calming fruity notes like figs, peach & apricot, finish with hints of milk tea aftertaste. A comforting cuppa perfect for any occasion. | | It's time for the first Blaq Coffee Tasting Box of 2022! This January features our long time roaster partner Brew & Bread. We have picked all only the new arrival coffees into this box. Get ready for an exciting coffee tasting experience with fresh crop coffees 😍 January Box ships out today and you can expect to receive 10th of January, Get yours now! | | You may like these coffees | | | Brazil Fazenda Passeio Natural | | | | | Share the news to your friends and families. | | | |
Write a newfangled code fragment at an earlier stage to use it. Then call another method and make sure their input is the correct one. The s...
-
If you are having trouble viewing this email, click here. reader ...
-
If you are having trouble viewing this email, click here. reader ...
-
admin posted: " [Download] Abdul Bari All Courses for Free Download - Google Drive Links [Abdul Bari] Learn Core JAV...
|
|
|
|
|