I'm very new to R and am coding a two player game where the first player knows the goal of the game and the second does not, yet they are helping.
I'm attempting to code for the first player and I want to create code that picks a move based on if it helps move the goal of the game forward.
Goal of the game::: to move all red colored pieces to the second section (section B).
Values for the vector::
-If the move helps the game forward it would have the value 1
-If it doesn't (but doesn't obstruct the goal like moving to an empty space) it would be 0
-If it obstructs the goal (like moving on top of a red piece) it would equal -1
I am looking to create code that loops through a data set and generates a utility vector for each piece on the top of the column based on the goal and the vector values described above.
Anyway, here's some sample code:
#for reference of what the numbers mean:
red <- 2
non.red <- 1
empty <- 0
#code for the initial game board
One<- c(1,1,2,1,1,1,2,1,0,2,1,1,2,1,2,1,1,0)
Two <- c(1,1,0,2,0,0,1,1,0,0,1,1,1,2,0,0,1,0)
Three <-c(2,0,0,0,0,0,1,2,0,0,0,0,2,0,0,0,0,0)
Four <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
Five <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
Board.game.act <- rbind.data.frame(Five, Four, Three, Two, One)
colnames(Board.game.act) <- c("1A", "2A", "3A", "4B", "5B", "6B", "7C", "8C", "9C", "10D", "11D", "12D", "13E", "14E", "15E", "16F", "17F", "18F")
#goal is to move all blues to columns 4-6 or section "B"
#only top of the columns can be moved
#code output for desired utility vector would something like:
red.1 <- c(0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0)
non.2 <- c(-1,-1,0,0,0,-1,-1,0,-1,0,0,-1,-1,-1,0,0,0)
red.3 <- c(0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0)
red.4 <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
non.5 <- c(-1,0,-1,-1,0,-1,-1, 0,-1,0,0,-1,-1,-1,0,0,0)
non.6 <- c(-1,0,-1,0,0,-1,-1,0,-1,0,0,-1,-1,-1,0,0,0)
non.7 <- c(0,1,0,1,1,1,0,1,0,1,1,0,0,0,1,1,1)
red.8 <- c(0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0)
red.10 <- c(0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0)
non.11 <- c(-1,0,-1,0,0,0,-1,-1,0,-1,0,-1,-1,-1,0,0,0)
non.12 <- c(-1,0,-1,0,0,0,-1,-1, 0,-1,0,-1,-1,-1,0,0,0)
red.13 <- c(0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0)
red.14 <- c(0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0)
red.15 <- c(0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0)
non.16 <- c(-1,0,-1,0,0,0,-1,-1,0,-1,0,0,-1,-1,-1,0,0)
non.17 <- c(-1,0,-1,0,0,0,-1,-1,0,-1,0,0,-1,-1,-1,0,0)
#I created the above utility vectors manually based on the first players possible first moves
If you could give me pointers as how to have my code generate these vectors by itself, I would appreciate it!
Thanks again!