class: center, middle, inverse, title-slide # Testing AI algorithms ## in games with Shiny ### Łukasz Wawrowski ### Why R?, 29-09-2019 --- # Hello! ### Łukasz Wawrowski [wawrowski.edu.pl](http://www.wawrowski.edu.pl/) - Poznań University of Economics and Business + statistics and survey methodology + poverty - DOJI S.A. + artificial intelligence + games --- # Challenge - take part in R&D project about AI in games -- - in team there are scientists with Excel and R knowledge -- - we designed a turn-based combat game -- - we need a prototype to test gameplay -- - we need some AI algorithms and test them --- # Solution <center><img src="img/R_logo.png" height="500"></center> --- # Expectations <center><img src="img/heroes.jpg" height="450"></center> [source](https://store.steampowered.com/app/297000/Heroes_of_Might__Magic_III__HD_Edition) --- # Hex map .pull-left[ ```r library(sp) coord <- matrix(c(0,0,0,15,10,15,10,0,0,0), ncol=2, byrow=T) pg <- Polygon(coord) ps <- Polygons(list(pg),1) sps <- SpatialPolygons(list(ps), proj4string = CRS(as.character(NA))) hexpoints <- spsample(sps, n=100, type="hexagonal", cellsize=1) hexgrid <- HexPoints2SpatialPolygons( hexpoints, dx = 1) ``` ] .pull-right[ <img src="img/hex_id2.png" height=500px> ] --- # Interactivity .pull-left[ <img src="img/shiny.png" height=400px> ] .pull-right[ ```r library(shiny) plotOutput(outputId, width = "100%", height = "400px", click = NULL, dblclick = NULL, hover = NULL, ...) ``` ] --- # Moving ```r library(rgeos) gContains() # whether point is unit gDistance() # distance between unit and aim gIntersects() # what is between unit and aim ``` --- # Artificial intelligence Assess possible actions for given game state: - probability of hitting the opponent - number of health points (HP) - the attack will eliminate the opponent - there is an obstacle on the shot line - movement causes exposure to the shot - ... -- Select the action that has the highest evaluation function. --- # [Game](https://lwawrowski.shinyapps.io/combatGame/) <img src="img/combat.png" height=500px> --- class: inverse, center, middle # Thank you! [wawrowski.edu.pl](http://www.wawrowski.edu.pl/)