什么是最有效的方法来产生所有可能的天际线(PC Game)药水组合? [英] What's the most efficient way of generating all possible combinations of skyrim (PC Game) potions?

查看:251
本文介绍了什么是最有效的方法来产生所有可能的天际线(PC Game)药水组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以每个成分有4个效果
http://www.uesp.net / wiki / Skyrim:成分

So each ingredient has 4 effects http://www.uesp.net/wiki/Skyrim:Ingredients

如果我结合了两种成分。这些药水将具有两套相交的奖励效果。我不能使用相同的成分两次。为了产生所有2种成分的可能性,我刚刚列出了成分的成分。我拿起列表的头,并将其与清单中的每个元素的其余部分进行比较,每次迭代删除头。这避免了重复。

If I combine two ingredients. The potions will have the bonus effects of where the two sets intersect. I can't use the same ingredient twice. To generate all 2 ingredient possibilities I just made a list of ingredient to effect pairs. I take the head of the list and compare it to the rest of the list for each element in the list deleting the head every iteration. That avoids dupes.

我被卡住了。我不知道如何生成3种成分组合而没有笨蛋。任何建议?

I'm stuck though. I don't know how to generate 3 ingredient combinations without dupes. Any suggestions?

推荐答案

听起来像每个人最喜欢的编程语言的工作, R

Sounds like a job for everybody's favorite programming language, R!

library(XML)
tables <- readHTMLTable('http://www.uesp.net/wiki/Skyrim:Ingredients', 
    stringsAsFactors=FALSE)
potions <- tables[[1]]
twoway <- data.frame(t(combn(potions$Name,2)))
threeway <- data.frame(t(combn(potions$Name,3)))

BAM!

> head(twoway)
               X1                  X2
1 Abecean Longfin          Bear Claws
2 Abecean Longfin                 Bee
3 Abecean Longfin        Beehive Husk
4 Abecean Longfin      Bleeding Crown
5 Abecean Longfin         Blisterwort
6 Abecean Longfin Blue Butterfly Wing
> head(threeway)
               X1         X2                  X3
1 Abecean Longfin Bear Claws                 Bee
2 Abecean Longfin Bear Claws        Beehive Husk
3 Abecean Longfin Bear Claws      Bleeding Crown
4 Abecean Longfin Bear Claws         Blisterwort
5 Abecean Longfin Bear Claws Blue Butterfly Wing
6 Abecean Longfin Bear Claws       Blue Dartwing

使用 write.csv 命令将表保存为csv文件。

Use the write.csv command to save the tables as csv files.

/编辑:说明我在做什么: XML 包含 readHTMLTable 功能,它将所有html表从网站作为data.frames并将其保存为列表。这个列表中的第一个表是我们想要的。 combn 功能查找所有2 - 路,3路和方式药剂名称的组合,并将结果作为矩阵。我使用t函数来转置此矩阵,因此每个组合是一行,然后将其转换为数据帧。这很容易扩展到n个成分的组合。

/ To explain what I'm doing: The XML package contains the readHTMLTable function, which pulls all the html tables from a website as data.frames and saves them as a list. The first table in this list is the one we want. The combn function finds all the 2-way, 3-way, and n way combinations of potion names, and returns the result as a matrix. I use the t function to transpose this matrix, so each combination is one row, and then convert it to a data frame. This easily extends to combinations of n ingredients.

/编辑2:我写了一个函数来将n路表保存到用户指定的csv文件。我也重新工作了一点,因为转移巨大的学分在计算上是昂贵的。这个版本应该允许你计算4路表,虽然需要很长时间,我不知道它是否与游戏相关。

/Edit 2: I wrote a function to save the n-way table to a user-specified csv file. I also re-worked it a bit, because transposing huge matricies is computationally expensive. This version should allow you to calculate the 4-way table, although it takes a long time and I don't know if it's relevant to the game.

nway <- function(n, filepath, data=potions) {
    nway <- combn(data$Name, n, simplify = FALSE)
    nway <- do.call(rbind,nway)
    write.csv(nway,filepath, row.names=FALSE)
}
nway(4,'~/Desktop/4way.csv')

/编辑3:这是一些代码来找到实际的工作药水。这不是很有效率,可能会大大改善:

/Edit 3: Here's some code to find the actual working potions. It's not very efficient and can probably be greatly improved:

#Given an ingredient, lookup effects
findEffects <- function(Name) { #Given a name, lookup effects
    potions[potions$Name==Name,3:6]
}

#2-way potions
intersectTwoEffects <- function(x) {
    Effects1 <- findEffects(x[1])
    Effects2 <- findEffects(x[2])
    Effects <- unlist(intersect(Effects1,Effects2))
    Effects <- c(x[1],x[2],Effects)
    length(Effects) <- 6
    names(Effects) <- NULL
    c(Effects,sum(is.na(Effects)))

}
twoway <- lapply(twoway,intersectTwoEffects)
twoway <- do.call(rbind,twoway)
twoway <- twoway[twoway[,7]<4,-7] #remove combos with no effect
write.csv(twoway,'~/Desktop/twoway.csv',row.names=FALSE)

#3-way potions
intersectThreeEffects <- function(x) {
    Effects1 <- findEffects(x[1])
    Effects2 <- findEffects(x[2])
    Effects3 <- findEffects(x[3])
    Effects <- c(intersect(Effects1,Effects2),intersect(Effects1,Effects3),intersect(Effects2,Effects3))
    Effects <- unlist(unique(Effects))
    Effects <- c(x[1],x[2],x[3],Effects)
    length(Effects) <- 8
    names(Effects) <- NULL
    c(Effects,sum(is.na(Effects)))

}
threeway <- lapply(threeway,intersectThreeEffects)
threeway <- do.call(rbind,threeway)
threeway <- threeway[threeway[,9]<5,-9] #remove combos with no effect
write.csv(threeway,'~/Desktop/threeway.csv',row.names=FALSE)

这篇关于什么是最有效的方法来产生所有可能的天际线(PC Game)药水组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆