An efficient way to give gifts in Stardew Valley

I was playing Stardew Valley recently... well, it consumed much of my weekends...

In the game, the player has to give gifts to all villagers to keep a good relationship with them. There is an official page displaying each one's preference, wiki. However, my life will be much easier if I can minimize the amount of distinct gifts I carry every day. When there is an optimization question, there is an analytical solution 🙂

My approach:

Use wiki's data as input, then identify the items that are favored by more than one villagers, and easy to obtain regardless of the season...as a result, I can arrange production and carriage easily and efficiently.

Output:

A network graph that shows how villagers are connected by gifts.

screen-shot-2016-11-06-at-6-52-54-pm

Source codes:

gift = read.csv("stardew valley gift.csv/Sheet 1-Table 1.csv", stringsAsFactors = F)

names(gift)

expand.gift = apply(gift, 1, 
      function (x) {
        gift_list = unlist(strsplit(x[2],"\n "))
        data.frame(v = x[1], g = gift_list)
        }
      )
expand.gift = do.call(rbind, expand.gift)

expand.gift$v = gsub("\n","",expand.gift$v)
expand.gift$g = gsub("[[:space:]]","",expand.gift$g)
expand.gift$v = paste0("v.",expand.gift$v)
names(expand.gift) = c("source","target")
write.csv(expand.gift, file = "expand.gift.csv", row.names = F)
expand.gift = subset(expand.gift, ! g %in% c("Prismatic Shard","Rabbit's Foot"))

expand.gift.mul = merge(expand.gift, expand.gift,
                        by.x = "v",by.y = "v")
expand.gift.mul = subset(expand.gift.mul, g.x!= g.y)

library(igraph)
gift.n = graph_from_edgelist(as.matrix(expand.gift.mul[,2:3]), T)
gift.n = as.undirected(gift.n, mode = "mutual")
V(gift.n)$size <- 1
l <- layout_with_kk(gift.n)
plot(gift.n,layout=l, vertex.label.cex	 = 0.7)

write_graph(gift.n, file = "svgift.gml",format = "gml")

Original dataset:
sheet-1-table-1.csv

Vector graph output:
svgift.pdf

1 thought on “An efficient way to give gifts in Stardew Valley

  1. Raabb Ajam

    LoL, dang it!

    Nice one, so what is the conclusion from those graph? What is the best easiest gift item? Diamond?

Comments are closed.