diff --git a/backend/app/models/gekanator_question.rb b/backend/app/models/gekanator_question.rb
index a4c838f..8f9b925 100644
--- a/backend/app/models/gekanator_question.rb
+++ b/backend/app/models/gekanator_question.rb
@@ -13,7 +13,10 @@ class GekanatorQuestion < ApplicationRecord
validates :condition, presence: true
validates :priority_weight,
presence: true,
- numericality: { greater_than: 0 }
+ numericality: {
+ greater_than: 0,
+ less_than_or_equal_to: 3
+ }
scope :accepted, -> { where(status: 'accepted') }
end
diff --git a/frontend/src/pages/GekanatorPage.tsx b/frontend/src/pages/GekanatorPage.tsx
index 7a42884..2eef5b6 100644
--- a/frontend/src/pages/GekanatorPage.tsx
+++ b/frontend/src/pages/GekanatorPage.tsx
@@ -125,7 +125,7 @@ const sourcePriorityOffset = (question: GekanatorQuestion): number => {
const priorityWeightOffset = (question: GekanatorQuestion): number =>
- (question.priorityWeight - 1) * -.8
+ (Math.min (3, Math.max (.2, question.priorityWeight)) - 1) * -.8
const createGameSeed = (): string => {
@@ -447,16 +447,162 @@ const softenNextQuestionIds = ({
}
+type ExclusiveConditionGroup =
+ | 'original-month'
+ | 'original-year'
+ | 'original-month-day'
+ | 'source'
+
+
+const exclusiveConditionGroupFor = (
+ condition: GekanatorQuestion['condition'],
+): ExclusiveConditionGroup | null => {
+ switch (condition.type)
+ {
+ case 'original-month':
+ return 'original-month'
+ case 'original-year':
+ return 'original-year'
+ case 'original-month-day':
+ return 'original-month-day'
+ case 'source':
+ return 'source'
+ default:
+ return null
+ }
+}
+
+
+const sameConditionValue = (
+ left: GekanatorQuestion['condition'],
+ right: GekanatorQuestion['condition'],
+): boolean => {
+ if (left.type !== right.type)
+ return false
+
+ const valueKeyFor = (condition: GekanatorQuestion['condition']): string => {
+ switch (condition.type)
+ {
+ case 'tag':
+ return condition.key
+ case 'source':
+ return condition.host
+ case 'original-year':
+ return String (condition.year)
+ case 'original-month':
+ return String (condition.month)
+ case 'original-month-day':
+ return condition.monthDay
+ case 'title-length-greater-than':
+ return String (condition.length)
+ case 'title-has-ascii':
+ return ''
+ }
+ }
+
+ return valueKeyFor (left) === valueKeyFor (right)
+}
+
+
+const monthForCondition = (
+ condition: GekanatorQuestion['condition'],
+): number | null => {
+ if (condition.type === 'original-month')
+ return condition.month
+
+ if (condition.type !== 'original-month-day')
+ return null
+
+ const month = Number (condition.monthDay.split ('-')[0])
+ return Number.isInteger (month) ? month : null
+}
+
+
+const isMonthCrossMatch = (
+ candidate: GekanatorQuestion['condition'],
+ previous: GekanatorQuestion['condition'],
+): boolean => {
+ const candidateMonth = monthForCondition (candidate)
+ const previousMonth = monthForCondition (previous)
+ if (candidateMonth === null || previousMonth === null)
+ return false
+
+ const sameType = candidate.type === previous.type
+ if (sameType)
+ return false
+
+ return candidateMonth === previousMonth
+}
+
+
+const isExclusiveContradiction = (
+ candidate: GekanatorQuestion['condition'],
+ previous: GekanatorQuestion['condition'],
+): boolean => {
+ const candidateGroup = exclusiveConditionGroupFor (candidate)
+ const previousGroup = exclusiveConditionGroupFor (previous)
+
+ if (candidateGroup !== null && candidateGroup === previousGroup)
+ return !(sameConditionValue (candidate, previous))
+
+ const candidateMonth = monthForCondition (candidate)
+ const previousMonth = monthForCondition (previous)
+ if (candidateMonth !== null && previousMonth !== null)
+ return candidateMonth !== previousMonth
+
+ return false
+}
+
+
+const contradictionPenaltyFor = ({
+ question,
+ answers,
+}: {
+ question: GekanatorQuestion
+ answers: GekanatorAnswerLog[]
+}): number => {
+ return answers.reduce ((sum, answer) => {
+ const previous = answer.questionCondition
+ if (!(previous))
+ return sum
+
+ switch (answer.answer)
+ {
+ case 'yes':
+ return sum + (isExclusiveContradiction (question.condition, previous) ? 100 : 0)
+ case 'partial':
+ return sum + (isExclusiveContradiction (question.condition, previous) ? 25 : 0)
+ case 'no':
+ return sum + (
+ sameConditionValue (question.condition, previous)
+ || isMonthCrossMatch (question.condition, previous)
+ ? 40
+ : 0)
+ case 'probably_no':
+ return sum + (
+ sameConditionValue (question.condition, previous)
+ || isMonthCrossMatch (question.condition, previous)
+ ? 20
+ : 0)
+ default:
+ return sum
+ }
+ }, 0)
+}
+
+
const chooseQuestion = ({
posts,
questions,
scores,
+ answers,
askedIds,
gameSeed,
}: {
posts: Post[]
questions: GekanatorQuestion[]
scores: Map
{phase === 'intro' ? '投稿を読み込んでゐます...' : '前回のグカネータ状態を復元してゐます...'}
)} - {Boolean (error) &&投稿を読み込めませんでした.
} + {(Boolean (error) || Boolean (acceptedQuestionsError)) + &&グカネータの質問データを読み込めませんでした.
} - {phase === 'intro' && !(isLoading) && posts.length > 0 && ( + {phase === 'intro' && readyToStart && (