-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
140 lines (140 loc) · 7.82 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
beA<- function(x){As= rep("A",length(x))}
MakeWeapon<- function(WeaponList){
WeaponEffects<-WeaponList[[1]]
WeaponPrice<- WeaponList[[2]]
WeaponName<-WeaponList[[3]]
nameElements<-c("anonomous")
sampleMax<-min(nrow(WeaponEffects),nrow(WeaponPrice),nrow(WeaponName))
numData=ncol(WeaponEffects)
Output<-WeaponEffects[1,]
cost<-rep(1,numData)
randVect= sample(1:sampleMax,numData)
for(iii in 1:numData){
Output[1,iii]<-WeaponEffects[randVect[iii],iii]
cost[iii]<-WeaponPrice[randVect[iii],iii]
nameElements[length(nameElements)+1]<-WeaponName[randVect[iii],iii]
}
i <- sapply(Output, is.factor)
nameElements<-nameElements[nameElements !=""]
nameElements<-nameElements[!is.na(nameElements)]
FirstHalf<-substring(nameElements , 2)[substring(nameElements , 1, 1)=="<"]
LastHalf<-substring(nameElements , 2)[substring(nameElements , 1, 1)==">"]
Whole<-substring(nameElements , 2)[substring(nameElements , 1, 1)=="^"]
name<-paste("Nameless",sample(1:999,1),"-",sample(1:99,1))
if( length(Whole)+min(length(FirstHalf),length(LastHalf)) >0){
if(sample(1:(length(Whole)+min(length(FirstHalf),length(LastHalf))),1)>length(Whole)){
name<-paste(sample(FirstHalf,1),sample(LastHalf,1))
}else{
name<-sample(Whole,1)
}
}
Output[i] <- lapply(Output[i], as.character)
cost[colnames(WeaponEffects) == 'Price']<- exp(rnorm(1,0,0.04))
Output[1,"Price"]<-round(prod(cost))
Output[1,"Name"]<-name
Output<-Output[,c(1,length(Output),2:(length(Output)-1))]
return(list(cost,Output))
}
CSV2WepList<-function(FileName){
WepFile <- read.csv(FileName, sep=";",stringsAsFactors=FALSE,blank.lines.skip=FALSE)
ColsNeeded<-(length(WepFile))/3
WepEffects<-WepFile[-101,3*(1:ColsNeeded)-2]
WepPrice<-WepFile[-101,3*(1:ColsNeeded)-1]
WepName<-WepFile[-101,3*(1:ColsNeeded)]
colnames(WepEffects)[colnames(WepEffects) == 'X.7'] <- 'Price'
colnames(WepPrice)<- colnames(WepEffects)
colnames(WepName)<- colnames(WepEffects)
WepList<- list(WepEffects,WepPrice,WepName)
}
RevolverList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Revolvers.csv")
SwordList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/SwordList.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
PistolList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Pistols.csv")
ShotgunList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Shotgun.csv")
RifleList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Rifles.csv")
FireArms<-list(RevolverList,PistolList,RifleList,ShotgunList)
MeleeWeps<-list(KnifeList,SwordList)
GeneralWeps<-list(RevolverList,KnifeList,SwordList,PistolList,ShotgunList,RifleList)
BigList<-list(GeneralWeps,FireArms,MeleeWeps)
MakeWeaponShop<-function(WeaponLists, distribution=NULL, Filters=NULL, numItems=10,output=FALSE,seed=0){
if(seed>0){
set.seed(seed)
}
if(is.null(distribution)){
distribution<-(1:length(WeaponLists))
}
ShopList<- MakeWeapon(WeaponLists[[1]])[[2]]
for(iii in 1:numItems){
NextItem<-NULL
typeSelect<-sample(distribution,1)
while(is.null(NextItem)){
NextItem<- MakeWeapon(WeaponLists[[typeSelect]])
##Make an weapon to add to the list.
##Reject the item if it is outside scope somehow.
if(is.numeric(Filters$topPrice)){
if(Filters$topPrice < NextItem[[2]][3] && runif(1)>0.003){ ##If you are over the top price. That bad. But small get ou clause.
NextItem=NULL
}
}
if(is.numeric(Filters$botPrice) && !is.null(NextItem)){
if(Filters$botPrice > NextItem[[2]][3] && runif(1)>0.003){ ##If you are below the bottom price. That bad. But small get out clause.
NextItem=NULL
}
}
}
ShopList<-rbind(ShopList,NextItem[[2]])
}
ShopList<-ShopList[-1,]
attach(ShopList)
ShopList<-ShopList[order(Type,Price),]
detach(ShopList)
row.names(ShopList)<-1:numItems
if(output){
View(ShopList)
}
return(ShopList)
}
library(readr)
SwordList <- read_csv("~/Documents/RProjects/StarTraveller/SwordList.csv")
View(SwordList)
library(readr)
Shotgun <- read_delim("~/Documents/RProjects/StarTraveller/Shotgun.csv",
";", escape_double = FALSE, trim_ws = TRUE)
View(Shotgun)
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Revolvers.csv")
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/SwordList.csv")
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
RevolverList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Revolvers.csv")
SwordList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/SwordList.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
ClubList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
PistolList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Pistols.csv")
ShotgunList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Shotgun.csv")
RifleList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Rifles.csv")
RevolverList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Revolvers.csv")
SwordList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/SwordList.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
ClubList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
PistolList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Pistols.csv")
ShotgunList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Shotgun.csv")
RifleList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Rifles.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
RevolverList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Revolvers.csv")
SwordList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/SwordList.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
ClubList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
PistolList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Pistols.csv")
ShotgunList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Shotgun.csv")
RifleList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Rifles.csv")
RevolverList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Revolvers.csv")
SwordList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/SwordList.csv")
KnifeList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/KnifeList.csv")
ClubList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/ClubList.csv")
PistolList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Pistols.csv")
ShotgunList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Shotgun.csv")
RifleList<-CSV2WepList("https://raw.githubusercontent.com/alastair-JL/StarTraveller/master/Rifles.csv")