Category Archives: software

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

install Rodeo on OS X El Captain

Today I try to install Rodeo in order to use python for data analysis on my macbook. It is a new macbook (and the New Macbook) so I started everything from scratch. I installed Anaconda as recommended and then I installed iPython notebook. Everything worked fine.

$ python
Python 3.5.1 |Anaconda 2.4.1 (x86_64)| (default, Dec  7 2015, 11:24:55) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Then I tried to start Rodeo, hmm, error message: "Bad news. Rodeo cannot start".

What can I do? I searched on the internet but found nothing. I can use both ipython and python from my terminal so I thought that could not be a problem. Then I made a guess - there must be something wrong with environment variables. I tried to echo my environment variables from the terminal:

$ echo $PATH
/Users/Liyun/anaconda/bin:/Users/Liyun/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin

It looks fine to me. Then I opened Rodeo again,  discarded the error message,  and opened its preference tab. Wait, I can specify the python I want to use here, and by default it is /user/bin/python! So I tried this python,

$ /usr/bin/python
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Apparently, my macbook somehow comes with python 2.7. I changed the python path in Rodeo's preferences tab to /Users/Liyun/anaconda/bin/python and restarted Rodeo. This time it worked perfectly. Well, I guess for whatever reason Rodeo is trying to use the old python although I have installed Anaconda for it.

Add shortcut for "Export -> PDF(pdflatex)" on LyX's toolbar

Recently I got annoyed by LyX's inconvenient "Export -> PDF(pdflatex)" command.  Thus, I decide to modify my toolbar in LyX. Particularly, since I don't need the Update function (not an Adobe Reader user...), so I just removed it as well.

Today's aim: add an export shortcut for the menu File -> Export -> PDF(pdflatex), both keyboard shortcut and a button on the toolbar.

To modify LyX's toolbar, you need to go to its installation folder and find "stdtoolbars.inc". Mine is under the default path: "C:\Program Files\LyX20\Resources\ui". Then please find

Toolbar "view/update" "View/Update"
Item "View" "buffer-view"
Item "Update" "buffer-update"

After this, if you want to keep the Update button, then add this line after it:

Item "Export" "buffer-export pdflatex"

The result is shown like below

Or you can do it like me, just put the Update line into comment, i.e.

Toolbar "view/update" "View/Update"
Item "View" "buffer-view"
#Item "Update" "buffer-update"
Item "Export" "buffer-export pdflatex"

Moreover, if you love keyboard shortcut better than buttons on the toolbar, then please follow a few steps:

  1. go to "Tools->Preferences->Editing->shorcuts"
  2. under the "function" column, there is "document and window", then find "buffer-update" and remove it.
  3. find "buffer-export-custom", modify it to "buffer-export pdflatex" and configure the keyboard shortcuts as "ctrl+shift+R". (If you want to keep the shortcut for update, please choose another keyboard combination as you like)

Now you are able to use the keyboard shortcut for " File -> Export -> PDF(pdflatex)" as well! Enjoy!

Note: in similar ways, you can modify all the toolbar and shortcut you like!

ctrl+shift+R