Task dossier

Card Sorting Task (WCST-style)

T000016T000016-card-sortingDraftWeb preview availableUpdated Jun 21, 2026

Rule-based card sorting task for cognitive flexibility and set-shifting

Card Sorting Task (WCST-style) flow diagram
Card Sorting Task (WCST-style) flow diagram
Preview path
This task ships with a matched HTML companion so the browser preview can stay aligned to the canonical local repository.
Quick start
Clone locally, then follow the README for install and run instructions.
git clone https://github.com/TaskBeacon/T000016-card-sorting.git
cd T000016-card-sorting
# Follow the README for local setup and run steps

Card Sorting Task (WCST-style)

Maturity: draft

FieldValue
NameCard Sorting Task (WCST-style)
Versionv0.1.0-dev
URL / Repositoryhttps://github.com/TaskBeacon/T000016-card-sorting
Short DescriptionRule-based card sorting task for cognitive flexibility and set-shifting
Created ByTaskBeacon
Date Updated2026-02-17
PsyFlow Version0.1.9
PsychoPy Version2025.1.1
ModalityBehavior
LanguageChinese
Voice Namezh-CN-YunyangNeural

1. Task Overview

This task implements a WCST-style card sorting paradigm in which participants classify target cards according to a currently active rule (color, shape, or number). The rule changes by block, and each trial requires mapping the target card to one of four reference cards using keys 1-4. The implementation supports human, qa, and sim modes, includes trigger emissions for all major phases, and logs trial-level behavioral outcomes from config-driven rule conditions plus deterministic in-trial target generation.

2. Task Flow

Task Flow

Block-Level Flow

StepDescription
1. Parse runtime mode and configmain.py resolves mode (human, qa, sim) and loads the selected YAML profile into TaskSettings.
2. Build participant contextHuman mode opens SubInfo form; QA uses subject_id=qa; sim uses session participant ID.
3. Initialize runtimeWindow/keyboard are initialized; trigger runtime uses mock in QA/sim and configured driver in human mode.
4. Load stimuliStimBank preloads all configured stimuli (fixation, rule cue, card images, feedback, block break, goodbye).
5. Build block trial conditionsBlockUnit.generate_conditions(...) uses the built-in generator to create plain rule-label conditions per block (e.g., repeated color labels for the color block).
6. Start experimentSend exp_onset trigger and show instruction screen; wait for continue key.
7. Enter block loopFor each of total_blocks=3, choose rule by index from conditions=[color, shape, number].
8. Optional countdownHuman mode shows a 3-second countdown before block start.
9. Run BlockUnitBlock sends block_onset, runs trials from plain rule labels, then sends block_end.
10. Compute block summaryAfter each block, compute accuracy and score from block trial data.
11. Show block breakPresent formatted rule-specific block break text (block_break_color/shape/number) with block index, accuracy, and total score.
12. FinalizeShow good_bye with final score, send exp_end, save CSV, close trigger runtime, and quit PsychoPy.

Trial-Level Flow

StepDescription
1. Load trial conditionrun_trial.py receives one rule label (color / shape / number), allocates a trial ID, and deterministically samples a target-card feature combination plus correct key.
2. Cue phaseShow rule_cue for cue_duration=0.4s; emit rule-specific cue trigger (color_cue_onset / shape_cue_onset / number_cue_onset).
3. Anticipation phaseShow fixation for anticipation_duration=0.2s with anticipation_onset trigger.
4. Target phaseDraw target card plus four reference cards; open response window (target_duration=2.0s) for keys 1,2,3,4; emit target_onset, key_press, and no_response as applicable.
5. Response state writebackStore response key, correctness (hit), correct key, and target features into trial data.
6. Feedback phaseShow either feedback_correct or feedback_incorrect for feedback_duration=0.6s; emit feedback_onset.
7. ITI phaseShow fixation for iti_duration=0.3s with iti_onset trigger.
8. Return trial recordReturn fully populated trial dictionary to block-level collector.

Condition Generation Logic

ComponentDescription
Feature spacesFixed feature sets in src/utils.py: 4 colors (RED/GREEN/BLUE/YELLOW), 4 shapes (CIRCLE/TRIANGLE/STAR/SQUARE), 4 numbers (1-4).
BlockUnit integrationmain.py uses the basic BlockUnit.generate_conditions(...) path with plain config condition labels.
Block condition contentEach block condition is a simple rule label (color, shape, number), which keeps block logs easy to audit.
Trial spec samplersample_card_trial_spec(rule, key_list, seed) in src/utils.py shuffles feature indices and computes the rule-dependent correct key using task.key_list.
Target image bindingrun_trial.py generates the target image path at trial runtime from the sampled feature tuple.
AuditabilityRule assignment is visible in block conditions, while target-feature sampling is deterministic from block seed + trial ID and logged in trial data (trial_seed, condition_id).

Controller Logic

ComponentDescription
Adaptive controllerNot used in this task.
RationaleT000016 does not require online RT-window adjustment or staircase control.
Replacement patternsrc/utils.py only provides lightweight target-feature sampling helpers; main.py uses standard BlockUnit.generate_conditions(...).

Other Logic

ComponentDescription
ScoringFeedback state sets delta=1 for correct and delta=0 otherwise; block and final scores sum these deltas.
Rule cue/break textParticipant-facing Chinese rule text is defined directly in config stimuli (rule_cue_color/shape/number, block_break_color/shape/number).
Trial context plumbingEvery major stage (rule_cue, pre_choice_fixation, card_choice_response, choice_feedback, iti) calls set_trial_context(...) for responder/simulation compatibility and auditability.

Runtime Context Phases

Phase LabelMeaning
rule_cuerule cue stage in src/run_trial.py responder context.
pre_choice_fixationpre choice fixation stage in src/run_trial.py responder context.
card_choice_responsecard choice response stage in src/run_trial.py responder context.
choice_feedbackchoice feedback stage in src/run_trial.py responder context.
itiinter-trial fixation stage in src/run_trial.py responder context.

3. Configuration Summary

All settings are defined in config/config.yaml.

a. Subject Info

FieldMeaning
subject_idRequired participant ID, integer, 3 digits, constrained to 101-999.

b. Window Settings

ParameterValue
size[1280, 720]
unitspix
screen0
bg_colorblack
fullscreenfalse
monitor_width_cm35.5
monitor_distance_cm60

c. Stimuli

NameTypeDescription
fixationtextCenter + shown in anticipation and ITI.
instruction_texttextChinese task instruction with key mapping (1-4) and start prompt.
rule_cue_color / shape / numbertextRule-specific cue text (当前规则:颜色 / 当前规则:形状 / 当前规则:数量) shown at trial start.
target_cardimageTarget card image rebuilt per trial from the sampled feature combination.
ref_card_1imageReference card #1 (left-most response option).
ref_card_2imageReference card #2.
ref_card_3imageReference card #3.
ref_card_4imageReference card #4 (right-most response option).
feedback_correcttextPositive feedback (正确).
feedback_incorrecttextError feedback (错误).
block_break_color / shape / numbertextRule-specific inter-block summary with accuracy and score.
good_byetextFinal completion screen with total score.

d. Timing

PhaseDuration
cue0.4 s
anticipation0.2 s
target response window2.0 s
feedback0.6 s
iti0.3 s

e. Triggers

EventCode
exp_onset98
exp_end99
block_onset100
block_end101
color_cue_onset20
shape_cue_onset21
number_cue_onset22
anticipation_onset25
target_onset30
key_press40
no_response41
feedback_onset50
iti_onset60

f. Condition Sampling

ParameterValue
seed sourcesettings.block_seed[block_i] (PsyFlow-generated per block)
random sourcePython random.Random(trial_seed), where trial_seed = block_seed * 1000 + trial_id
rule typescolor, shape, number
response spacekeys 1-4
adaptation styleNo adaptive controller; basic BlockUnit condition generation + deterministic in-trial sampling

4. Methods (for academic publication)

Participants completed a rule-based card sorting task designed to probe set-shifting and cognitive flexibility. Before the task started, instructions explained that each trial required classifying a target card using one of four response keys (1-4) corresponding to four reference cards displayed at the bottom of the screen. The active rule was provided by a cue at the beginning of each trial and changed across blocks (color, shape, number). Trials were organized into three blocks with 32 trials each (96 total trials), with one rule per block.

Each trial began with a rule cue (0.4 s), followed by a short anticipation fixation (0.2 s). The target card and reference cards were then displayed, and participants had up to 2.0 s to respond. Responses were evaluated against the rule-defined correct key based on the active rule and explicit trial feature specification. Feedback was shown for 0.6 s as either correct or incorrect, followed by a 0.3 s inter-trial fixation interval. Event triggers were emitted at experiment, block, and phase transitions to support synchronization and downstream analysis.

A task utility deterministically samples per-trial feature combinations (color, shape, number) from the active rule and computes rule-specific correct responses using the configured key list. Block-level summaries report accuracy and accumulated score using rule-specific break screens defined in config. This structure supports reproducible behavioral measurement of rule maintenance, rule switching across blocks, and response accuracy under explicit rule constraints while keeping trial logic easy to audit.