Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji enhance v3 #324

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 66 additions & 20 deletions static/tools/enhance/enrich-emoji.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,81 @@
var epoch = new Date("2021-06-19T00:00:00")
var solutionCount = 2309

function getPuzzleDate (num) {
function getPuzzleDate(num) {
var startDate = new Date(epoch)
var puzzleDate = startDate.setHours(0, 0, 0, 0) + (num * 864e5)
return (new Date(puzzleDate)).toISOString().substr(0,10)
return (new Date(puzzleDate)).toISOString().substr(0, 10)
}

function analyzeEmoji (input) {
function analyzeEmoji(input) {
var title = input.match(/Wordle [0-9]* [1-6]{1}\/6\*?/)
var titlePieces = title[0].split(' ')
var puzzleNum = parseInt(titlePieces[1], 10)
var puzzleDate = getPuzzleDate(puzzleNum)
var guessPieces = titlePieces[2].split("")
var [guessCount, slash, allowed, modeStr] = guessPieces

var results = input.match(/[🟩🟨⬛️]*/g)
.filter(r => r !== '')
.map((line) => {
return [...line]
.filter(a => /[^\ufe0f]/.test(a))
.map((char) => {
if (char === '🟩') {
return 'correct'
} else if (char === '🟨') {
return 'present'
} else {
return 'absent'
}
})
})
isNyt =
isSlackLight =
isSlackDark =

var nytSharePattern = /[🟩🟨⬛️]{5,10}/g
var slackSharePattern = /(\:(large_green_square|black_large_square|large_yellow_square)\:){5}/g
var slackSharePatternLight = /(\:(large_green_square|white_large_square|large_yellow_square)\:){5}/g
var results = []
console.log(`input: ${input}`)
if (input.match(nytSharePattern)) {
console.log('mode: nyt share')
results = input.match(nytSharePattern)
.filter(r => r !== '')
.map((line) => {
return [...line]
.filter(a => /[^\ufe0f]/.test(a))
.map((char) => {
if (char === '🟩') {
return 'correct'
} else if (char === '🟨') {
return 'present'
} else {
return 'absent'
}
})
})
} else if (input.match(slackSharePattern)) {
console.log('mode: slack share dark')
var slackTilePattern = /\:(large_green_square|black_large_square|large_yellow_square)\:/g
results = input.match(slackSharePattern)
.filter(r => r !== '')
.map((line) => {
return line.match(slackTilePattern)
.map((char) => {
if (char === ':large_green_square:') {
return 'correct'
} else if (char === ':large_yellow_square:') {
return 'present'
} else if (char === ':black_large_square:') {
return 'absent'
}
})
})
} else if (input.match(slackSharePatternLight)) {
console.log('mode: slack share dark')
var slackTilePatternLight = /\:(large_green_square|white_large_square|large_yellow_square)\:/g
results = input.match(slackSharePatternLight)
.filter(r => r !== '')
.map((line) => {
return line.match(slackTilePatternLight)
.map((char) => {
if (char === ':large_green_square:') {
return 'correct'
} else if (char === ':large_yellow_square:') {
return 'present'
} else if (char === ':white_large_square:') {
return 'absent'
}
})
})
}

var enrichedResults = results.map((lineStatuses) => {
var lineEmoji = lineStatuses.map((status) => {
Expand Down Expand Up @@ -58,8 +104,8 @@ function analyzeEmoji (input) {
}
})

var puzzleScore = enrichedResults.reduce((memo, result) => {
return memo + result.lineScore
var puzzleScore = enrichedResults.reduce((memo, result) => {
return memo + result.lineScore
}, 0)

return {
Expand Down
57 changes: 54 additions & 3 deletions static/tools/enhance/enrich-emoji.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Wordle 234 5/6*
🟩🟩🟩🟩🟩
`
const output = lib(wordle)
console.log(output)
// console.log(output)

assert.equal(output.puzzleNum, 234)
assert.equal(output.puzzleScore, 27)
Expand All @@ -31,14 +31,65 @@ Wordle 466 4/6*
🟩🟩🟩🟩🟩
`
const output = lib(wordle)
console.log(output)
// console.log(output)

assert.equal(output.puzzleNum, 466)
assert.equal(output.isHardMode, true)
assert.equal(output.puzzleScore, 23)
assert.equal(output.puzzleDate, '2022-09-28')
assert.equal(output.guessCount, 4)
}
},
function copyFromWhatsApp () {
const wordle = `
Wordle 449 4/6*

⬛️⬛️⬛️⬛️⬛️
🟩⬛️🟨🟩⬛️
🟩🟨⬛️🟩⬛️
🟩🟩🟩🟩🟩
`
const output = lib(wordle)
// console.log(output)

assert.equal(output.puzzleNum, 449)
assert.equal(output.isHardMode, true)
assert.equal(output.puzzleScore, 20)
assert.equal(output.puzzleDate, '2022-09-11')
assert.equal(output.guessCount, 4)
},
function copyFromSlackDarkAbsent () {
const wordle = `
Wordle 467 4/6*
:black_large_square::black_large_square::black_large_square::black_large_square::black_large_square:
:black_large_square::black_large_square::large_green_square::black_large_square::large_yellow_square:
:large_yellow_square::large_yellow_square::large_green_square::large_yellow_square::black_large_square:
:large_green_square::large_green_square::large_green_square::large_green_square::large_green_square:
`
const output = lib(wordle)
// console.log(output)

assert.equal(output.puzzleNum, 467)
assert.equal(output.isHardMode, true)
assert.equal(output.puzzleScore, 22)
assert.equal(output.puzzleDate, '2022-09-29')
assert.equal(output.guessCount, 4)
},
function copyFromSlackLightAbsent () {
const wordle = `
Wordle 468 3/6*
:white_large_square::white_large_square::white_large_square::large_green_square::white_large_square:
:large_green_square::white_large_square::white_large_square::large_green_square::white_large_square:
:large_green_square::large_green_square::large_green_square::large_green_square::large_green_square:
`
const output = lib(wordle)
console.log(output)

assert.equal(output.puzzleNum, 468)
assert.equal(output.isHardMode, true)
assert.equal(output.puzzleScore, 14)
assert.equal(output.puzzleDate, '2022-09-30')
assert.equal(output.guessCount, 3)
},
]

tests.forEach((t) => t())
65 changes: 44 additions & 21 deletions static/tools/enhance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,60 @@
<script type="text/javascript">
var epoch = new Date("2021-06-19T00:00:00")
var solutionCount = 2309
var report

function getPuzzleDate (num) {
function getPuzzleDate(num) {
var startDate = new Date(epoch)
var puzzleDate = startDate.setHours(0, 0, 0, 0) + (num * 864e5)
return (new Date(puzzleDate)).toISOString().substr(0,10)
return (new Date(puzzleDate)).toISOString().substr(0, 10)
}

function analyzeEmoji (input) {
function analyzeEmoji(input) {
var title = input.match(/Wordle [0-9]* [1-6]{1}\/6\*?/)
var titlePieces = title[0].split(' ')
var puzzleNum = parseInt(titlePieces[1], 10)
var puzzleDate = getPuzzleDate(puzzleNum)
var guessPieces = titlePieces[2].split("")
var [guessCount, slash, allowed, modeStr] = guessPieces

var results = input.match(/[🟩🟨⬛️]*/g)
.filter(r => r !== '')
.map((line) => {
return [...line]
.filter(a => /[^\ufe0f]/.test(a))
.map((char) => {
if (char === '🟩') {
return 'correct'
} else if (char === '🟨') {
return 'present'
} else {
return 'absent'
}
})
})
var nytSharePattern = /[🟩🟨⬛️]*/g
var slackSharePattern = /(\:(large_green_square|black_large_square|large_yellow_square)\:){5}/g
var results = []

if (input.match(nytSharePattern)) {
results = input.match(nytSharePattern)
.filter(r => r !== '')
.map((line) => {
return [...line]
.filter(a => /[^\ufe0f]/.test(a))
.map((char) => {
if (char === '🟩') {
return 'correct'
} else if (char === '🟨') {
return 'present'
} else {
return 'absent'
}
})
})
}

if (input.match(slackSharePattern)) {
var slackTilePattern = /\:(large_green_square|black_large_square|large_yellow_square)\:/g
results = input.match(slackSharePattern)
.filter(r => r !== '')
.map((line) => {
return line.match(slackTilePattern)
.map((char) => {
if (char === ':large_green_square:') {
return 'correct'
} else if (char === ':large_yellow_square:') {
return 'present'
} else if (char === ':black_large_square:') {
return 'absent'
}
})
})
}

var enrichedResults = results.map((lineStatuses) => {
var lineEmoji = lineStatuses.map((status) => {
Expand Down Expand Up @@ -67,8 +90,8 @@
}
})

var puzzleScore = enrichedResults.reduce((memo, result) => {
return memo + result.lineScore
var puzzleScore = enrichedResults.reduce((memo, result) => {
return memo + result.lineScore
}, 0)

return {
Expand Down