diff --git a/web/public/mtg/app.js b/web/public/mtg/app.js
index 248b3406..06f167b3 100644
--- a/web/public/mtg/app.js
+++ b/web/public/mtg/app.js
@@ -1,9 +1,10 @@
mode = 'PLAY'
allData = {}
total = 0
-unseenTotal = 0
probList = []
nameList = []
+weightedCards = []
+indWeighedCards = 0
k = 12
extra = 3
artDict = {}
@@ -50,13 +51,21 @@ fetchToResponse(firstFetch)
function putIntoMapAndFetch(data) {
putIntoMap(data.data)
+ if (whichGuesser == 'artist') {
+ newArtistData = createNewArtistMap()
+ allData = newArtistData[0]
+ total = newArtistData[1]
+ }
for (const [key, value] of Object.entries(allData)) {
nameList.push(key)
probList.push(
value.length + (probList.length === 0 ? 0 : probList[probList.length - 1])
)
- unseenTotal = total
+ for (let j = 0; j < value.length; j++) {
+ weightedCards.push(key)
+ }
}
+ shuffleArray(weightedCards)
window.console.log(allData)
window.console.log(total)
window.console.log(probList)
@@ -74,31 +83,35 @@ function putIntoMapAndFetch(data) {
} else if (whichGuesser === 'artist') {
document.getElementById('guess-type').innerText = 'Aesthetic Consultation'
}
+ window.console.log(whichGuesser)
setUpNewGame()
}
function getKSamples() {
let usedCounters = new Set()
- let currentTotal = unseenTotal
let samples = {}
let i = 0
- while (i < k) {
- let rand = Math.floor(Math.random() * currentTotal)
- let count = 0
- for (const [key, value] of Object.entries(allData)) {
- if (usedCounters.has(key)) {
- continue
- } else if (count >= rand) {
- usedCounters.add(key)
- currentTotal -= value.length
- unseenTotal--
- let randIndex = Math.floor(Math.random() * value.length)
- let arts = allData[key].splice(randIndex, 1)
- samples[arts[0].artImg] = [key, arts[0].normalImg]
- i++
+ let allCards = []
+ for (const [key, value] of Object.entries(allData)) {
+ for (let j = 0; j < value.length; j++) {
+ allCards.push(key)
+ }
+ }
+ shuffleArray(allCards)
+ for (let j = 0; j < allCards.length; j++) {
+ key = allCards[j]
+ value = allData[key]
+ if (usedCounters.has(key)) {
+ continue
+ } else {
+ window.console.log(key)
+ usedCounters.add(key)
+ let randIndex = Math.floor(Math.random() * value.length)
+ let arts = allData[key].splice(randIndex, 1)
+ samples[arts[0].artImg] = [key, arts[0].normalImg]
+ i++
+ if (i >= k) {
break
- } else {
- count += value.length
}
}
}
@@ -108,15 +121,18 @@ function getKSamples() {
}
}
let count = 0
- while (count < extra) {
- let rand = Math.floor(Math.random() * total)
- for (let j = 0; j < nameList.length; j++) {
- if (j >= rand) {
- if (usedCounters.has(nameList[j])) {
- break
- }
- usedCounters.add(nameList[j])
- count += 1
+ let ind = 0
+ shuffleArray(weightedCards)
+ for (let j = 0; j < weightedCards.length; j++) {
+ key = weightedCards[j]
+ value = weightedCards[key]
+ if (usedCounters.has(key)) {
+ continue
+ } else {
+ window.console.log(key)
+ usedCounters.add(key)
+ count++
+ if (count >= extra) {
break
}
}
@@ -124,12 +140,35 @@ function getKSamples() {
return [samples, usedCounters]
}
+function createNewArtistMap() {
+ let usedCounters = new Set()
+ let samples = {}
+ let i = 0
+ let newTotal = 0
+ while (i < k + extra) {
+ let rand = Math.floor(Math.random() * total)
+ let count = 0
+ for (const [key, value] of Object.entries(allData)) {
+ if (usedCounters.has(key)) {
+ continue
+ } else if (count >= rand) {
+ usedCounters.add(key)
+ samples[key] = value
+ newTotal += value.length
+ i++
+ break
+ } else {
+ count += value.length
+ }
+ }
+ }
+ return [samples, newTotal]
+}
+
function fetchToResponse(fetch) {
return fetch
.then((response) => response.json())
- .then((json) => {
- putIntoMapAndFetch(json)
- })
+ .then((json) => putIntoMapAndFetch(json))
}
function determineIfSkip(card) {
@@ -157,7 +196,8 @@ function determineIfSkip(card) {
card.set_type === 'token' ||
card.set_type === 'vanguard' ||
card.set_type === 'planechase' ||
- card.set_type === 'archenemy'
+ card.set_type === 'archenemy' ||
+ card.set_type === 'memorabilia'
) {
return true
}
@@ -241,7 +281,9 @@ function setUpNewGame() {
setWordsLeft()
// select new cards
+ window.console.log(k)
let sampledData = getKSamples()
+ window.console.log(k)
artDict = sampledData[0]
let randomImages = Object.keys(artDict)
shuffleArray(randomImages)
@@ -278,17 +320,32 @@ function checkAnswers() {
let incorrect = true
if (currCard.dataset.name) {
// remove image text
- let guess = removeSymbol(
- document.getElementById(currCard.dataset.name).innerText
- )
- let ans = removeSymbol(artDict[currCard.dataset.url][0])
- window.console.log(ans, guess)
+ let guessWithSymbol = document.getElementById(
+ currCard.dataset.name
+ ).innerHTML
+ let ansWithSymbol = artDict[currCard.dataset.url][0]
+ let guess = removeSymbol(guessWithSymbol)
+ let ans = removeSymbol(ansWithSymbol)
incorrect = ans !== guess
// decide if their guess was correct
+ // window.console.log(ans, guess, incorrect)
+ if (incorrect) {
+ window.console.log(
+ document.getElementById(currCard.dataset.name),
+ guess,
+ ans
+ )
+ document.getElementById(currCard.dataset.name).innerHTML =
+ '' + guessWithSymbol + '
' + ansWithSymbol
+ }
}
- if (incorrect) currCard.classList.add('incorrect')
- // tally some kind of score
- if (incorrect) score--
+ if (incorrect) {
+ currCard.classList.add('incorrect')
+ // tally some kind of score
+ score--
+ // show the correct answer
+ }
+
// show the correct card
currCard.style.backgroundImage =
"url('" + artDict[currCard.dataset.url][1] + "')"
diff --git a/web/public/mtg/importCards.py b/web/public/mtg/importCards.py
index 47dbcf5f..d02a99cd 100644
--- a/web/public/mtg/importCards.py
+++ b/web/public/mtg/importCards.py
@@ -26,20 +26,31 @@ def generate_initial_query(category):
'.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \
'+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure+not%3Adfc'
elif category == 'commander':
- string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl+or+legal%3Acommander+or+legal%3Abrawl%29'
+ string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl' \
+ '+or+legal%3Acommander+or+legal%3Abrawl%29'
# elif category == 'zombie':
# string_query += '-type%3Alegendary+type%3Azombie+-type%3Atoken'
# elif category == 'artifact':
# string_query += 't%3Aartifact&order=released&dir=asc&unique=prints&page='
elif category == 'artist':
- string_query += '%28a%3A"Carl+Critchlow"+or+a%3A"Chippy"+or+a%3A"Christopher+Moeller"+or+a%3A"christopher+rush"+or+a%3A"Daarken"+or+a%3A"Donato+Giancola"+or+a%3A"Douglas+Shuler"+or+a%3A"Eric+Deschamps"+or+a%3A"greg+staples"+or+a%3A"heather+Hudson"+or+a%3A"igor+kieryluk"+or+a%3A"Jeff+Miracola"+or+a%3A"johannes+voss"+or+a%3A"Julie+Baroh"+or+a%3A"kev+walker"+or+a%3A"Lius+Lasahido"+or+a%3A"Livia+Prima"+or+a%3A"Magali+Villeneuve"+or+a%3A"Mark+Poole"+or+a%3A"Mark+Tedin"+or+a%3A"Mark+Zug"+or+a%3A"Nils+Hamm"+or+a%3A"pete+venters"+or+a%3A"randy+gallegos"+or+a%3A"rebecca+guay"+or+a%3A"rk+post"+or+a%3A"rob+alexander"+or+a%3A"ron+spencer"+or+a%3A"Scott+M+Fischer"+or+a%3A"seb+mckinnon"+or+a%3A"steve+argyle"+or+a%3A"Svetlin+Velinov"+or+a%3A"Veronique+Meignaud"+or+a%3A"Wylie+Beckert"+or+a%3A“Amy+Weber”+or+a%3A“Dan+Frazier”+or+a%3A“David+Martin”+or+a%3A“DiTerlizzi”+or+a%3A“Ernanda+Souza”+or+a%3A“Franz+Vohwinkel”+or+a%3A“Phil+Foglio”+or+a%3A“Rachta+Lin”+or+a%3A“Thomas+M.+Baxa”+or+a%3A“Victor+Adame+Minguez”+or+a%3A“Volkan+Baǵa”%29+not%3Adfc'
+ string_query += '%28a%3A"Carl+Critchlow"+or+a%3A"Chippy"+or+a%3A"Christopher+Moeller"+or+a%3A"christopher+rush"' \
+ '+or+a%3A"Daarken"+or+a%3A"Donato+Giancola"+or+a%3A"Douglas+Shuler"+or+a%3A"Eric+Deschamps"' \
+ '+or+a%3A"greg+staples"+or+a%3A"heather+Hudson"+or+a%3A"igor+kieryluk"+or+a%3A"Jeff+Miracola"+or+' \
+ 'a%3A"johannes+voss"+or+a%3A"Julie+Baroh"+or+a%3A"kev+walker"+or+a%3A"Lius+Lasahido"+or+a%3A"Livia+Prima"' \
+ '+or+a%3A"Magali+Villeneuve"+or+a%3A"Mark+Poole"+or+a%3A"Mark+Tedin"+or+a%3A"Mark+Zug"+or+a%3A"Nils+Hamm"' \
+ '+or+a%3A"pete+venters"+or+a%3A"randy+gallegos"+or+a%3A"rebecca+guay"+or+a%3A"rk+post"+or+a%3A"rob+alexander"' \
+ '+or+a%3A"ron+spencer"+or+a%3A"Scott+M+Fischer"+or+a%3A"seb+mckinnon"+or+a%3A"steve+argyle"+or+' \
+ 'a%3A"Svetlin+Velinov"+or+a%3A"Veronique+Meignaud"+or+a%3A"Wylie+Beckert"+or+a%3A“Amy+Weber”+or+' \
+ 'a%3A“Dan+Frazier”+or+a%3A“David+Martin”+or+a%3A“DiTerlizzi”+or+a%3A“Ernanda+Souza”+or+a%3A“Franz+Vohwinkel”' \
+ '+or+a%3A“Phil+Foglio”+or+a%3A“Thomas+M.+Baxa”+or+a%3A“Victor+Adame+Minguez”+or' \
+ '+a%3A“Volkan+Baǵa”%29+artists%3D1'
# add category string query here
if category != 'artist':
- string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \
- '<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29+-set%3Acmb2+-set%3Acmb1+-set%3Aplist' \
- '%29'
+ string_query += '+-%28set%3Asld+%28cn>%3D231+cn<%3D233+or+cn>%3D436+cn<%3D440+or+cn>%3D321+cn<%3D324+or' \
+ '+cn>%3D185+cn<%3D189+or+cn>%3D138+cn<%3D142+or+cn>%3D364+cn<%3D368+or+cn%3A669+or+cn%3A670%29%29+' \
+ '-%28set%3Asta+cn>%3D64+cn<%3D126%29+-set%3Acmb2+-set%3Acmb1+-set%3Aplist'
string_query += '+-name%3A%2F%5EA-%2F+not%3Asplit+-st%3Amemorabilia' \
- '+language%3Aenglish&order=released&dir=asc&unique=prints&page='
+ '&order=released&dir=asc&unique=prints&page='
print(string_query)
return string_query
@@ -54,6 +65,11 @@ def generate_initial_special_query(category):
print(string_query)
return string_query
+# def generate_initial_artist_query():
+# string_query = 'https://api.scryfall.com/cards/search?q=artists%3D1+-st%3Afunny+not%3Adigital+-st%3Atoken+-t%3Avanguard+-st%3Amemorabilia+-t%3Ascheme+-t%3Aplane+-t%3APhenomenon&unique=art&as=grid&order=artist&page='
+# print(string_query)
+# return string_query
+
def fetch_and_write_all(category, query):
count = 1
@@ -228,6 +244,6 @@ if __name__ == "__main__":
print(category)
fetch_and_write_all_special(
category, generate_initial_special_query(category))
- print("artistList")
+ print("artistList")
with open('jsons/artistList.json', 'w') as f:
json.dump(artists, f)
diff --git a/web/public/mtg/index.html b/web/public/mtg/index.html
index fc381bd7..216e1791 100644
--- a/web/public/mtg/index.html
+++ b/web/public/mtg/index.html
@@ -263,7 +263,7 @@
id="artist"
name="whichguesser"
value="artist"
- onchange="updateSettingDefault(true, true, true, 'only include cards')"
+ onchange="updateSettingDefault(false, true, true, 'only include cards')"
/>