steveyehtw commited on
Commit
cb6638a
·
1 Parent(s): 89d57b6

Add independent Lessons 23–25 auction project and parent demo

Browse files
classroom_data/course.json CHANGED
@@ -458,6 +458,111 @@
458
  "submission": "REPORT.md 有問題、來源、方法與結果、程式可重跑,數字與報告一致、資料檔案與 DATA_SOURCE.md 都在、能親自說明數字與一段相關程式、AI 紀錄如實填寫;未使用也可以",
459
  "ai_note": "每人各自完成。允許使用外部 AI,保留實際使用與核對紀錄;沒有使用就如實註明。"
460
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  }
462
  ]
463
  }
 
458
  "submission": "REPORT.md 有問題、來源、方法與結果、程式可重跑,數字與報告一致、資料檔案與 DATA_SOURCE.md 都在、能親自說明數字與一段相關程式、AI 紀錄如實填寫;未使用也可以",
459
  "ai_note": "每人各自完成。允許使用外部 AI,保留實際使用與核對紀錄;沒有使用就如實註明。"
460
  }
461
+ },
462
+ {
463
+ "id": "week23",
464
+ "lesson": 23,
465
+ "title": "拍賣會先玩起來",
466
+ "project": "荒謬商品拍賣會",
467
+ "output": "修改一件商品或一條規則,完成一輪可試玩的公開拍賣。",
468
+ "workspace_id": "week23",
469
+ "template": true,
470
+ "guide": {
471
+ "goal": "修改一件商品或一條規則,完成一輪可試玩的公開拍賣。",
472
+ "flow": [
473
+ {
474
+ "time": "0–15 分",
475
+ "title": "先玩一輪",
476
+ "body": "用 100 枚虛擬幣競標一件荒謬商品。先看得標與流標,再看程式。"
477
+ },
478
+ {
479
+ "time": "15–60 分",
480
+ "title": "改出你的版本",
481
+ "body": "執行套版,改商品、起標或最低加價;找同學測超額與最低價。"
482
+ },
483
+ {
484
+ "time": "60–120 分",
485
+ "title": "交換試玩",
486
+ "body": "兩三人一組輪流主持,挑一個規則解釋 if 如何判斷。"
487
+ }
488
+ ],
489
+ "checklist": [
490
+ "能執行並完成一次開標",
491
+ "同學能玩出自己改的地方",
492
+ "測過一筆無效出價"
493
+ ],
494
+ "submission": "能執行並完成一次開標、同學能玩出自己改的地方、測過一筆無效出價"
495
+ }
496
+ },
497
+ {
498
+ "id": "week24",
499
+ "lesson": 24,
500
+ "title": "公開與秘密出價對決",
501
+ "project": "荒謬商品拍賣會",
502
+ "output": "讓同一商品走完兩種規則,並能解釋成交價從哪裡來。",
503
+ "workspace_id": "week23",
504
+ "template": true,
505
+ "guide": {
506
+ "goal": "讓同一商品走完兩種規則,並能解釋成交價從哪裡來。",
507
+ "flow": [
508
+ {
509
+ "time": "0–20 分",
510
+ "title": "先預測",
511
+ "body": "同一件商品、買家與預算;先寫下哪一種可能成交較高。"
512
+ },
513
+ {
514
+ "time": "20–65 分",
515
+ "title": "兩種玩法",
516
+ "body": "秘密輪先寫紙條再輸入,公開輪輪流加價。兩輪重新分配虛擬幣。"
517
+ },
518
+ {
519
+ "time": "65–120 分",
520
+ "title": "比結果",
521
+ "body": "比較兩輪成交價,測平手或流標,分享出價時看到了什麼。"
522
+ }
523
+ ],
524
+ "checklist": [
525
+ "兩種玩法都可結束",
526
+ "知道秘密出價不應讓旁人看到",
527
+ "能解釋一次觀察的限制"
528
+ ],
529
+ "submission": "兩種玩法都可結束、知道秘密出價不應讓旁人看到、能解釋一次觀察的限制"
530
+ }
531
+ },
532
+ {
533
+ "id": "week25",
534
+ "lesson": 25,
535
+ "title": "家長試玩日",
536
+ "project": "荒謬商品拍賣會",
537
+ "output": "完成一個家長能自己操作的拍賣展示,學生可講解一個判斷。",
538
+ "workspace_id": "week23",
539
+ "template": true,
540
+ "guide": {
541
+ "goal": "完成一個家長能自己操作的拍賣展示,學生可講解一個判斷。",
542
+ "flow": [
543
+ {
544
+ "time": "0–20 分",
545
+ "title": "自己試玩",
546
+ "body": "用 Console 和三位模擬買家練習,接著打開網頁版。"
547
+ },
548
+ {
549
+ "time": "20–75 分",
550
+ "title": "改一個地方",
551
+ "body": "換商品或模擬買家的出價上限,測空白、超額、正常成交與重新開始。"
552
+ },
553
+ {
554
+ "time": "75–120 分",
555
+ "title": "三分鐘展示",
556
+ "body": "家長完成兩輪,學生介紹一條規則與兩根長條,說明模擬與真人的差別。"
557
+ }
558
+ ],
559
+ "checklist": [
560
+ "家長可以單人完成兩輪",
561
+ "結果圖以共同尺度表示虛擬幣",
562
+ "能說出自己改的規則與測試結果"
563
+ ],
564
+ "submission": "家長可以單人完成兩輪、結果圖以共同尺度表示虛擬幣、能說出自己改的規則與測試結果"
565
+ }
566
  }
567
  ]
568
  }
classroom_data/templates/week23/README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Lesson 23|先玩、再改規則
2
+
3
+ 這個專題不需要之前的作品或資料。執行 `main.py`,只用虛擬幣,不使用真錢。
4
+
5
+ - 玩法:兩三人共用一個 Console,輪流出價。輸入 0 代表這次不加價;一整輪沒人加價就開標。
6
+ - 今天做:先改 PRODUCT、START 或 STEP 其中一項;讓同學玩得出差別。
7
+ - 交給同學測:測試超過預算、剛好符合最低出價、全部放棄。
8
+
9
+ L23–25 共用這個拍賣工作區。已經改過程式的同學,先暫存再取用別週範例;匯入整份套版會替換目前工作副本。也可以沿用原稿,只參考下一週的函式。
classroom_data/templates/week23/main.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """荒謬商品拍賣會:使用虛擬幣,所有資料只留在本次執行。"""
2
+
3
+ PRODUCT = "永遠慢一天的作業提醒手錶"
4
+ BUDGET = 100
5
+ START = 10
6
+ STEP = 5
7
+ PLAYERS = ["甲", "乙", "丙"]
8
+
9
+
10
+ def ask_bid(name, minimum):
11
+ if minimum > BUDGET:
12
+ return 0
13
+ while True:
14
+ raw = input(f"{name},出價 {minimum}~{BUDGET} 幣,0 放棄:").strip()
15
+ try:
16
+ bid = int(raw)
17
+ except ValueError:
18
+ print("請輸入整數。")
19
+ continue
20
+ if bid == 0 or minimum <= bid <= BUDGET:
21
+ return bid
22
+ print(f"出價需在 {minimum}~{BUDGET} 幣之間。")
23
+
24
+
25
+ def open_round(players):
26
+ """每次新出價都公開;全員一整輪沒有加價即開標。"""
27
+ winner, price = "", 0
28
+ while True:
29
+ changed = False
30
+ for name in players:
31
+ if name == winner:
32
+ continue
33
+ minimum = price + STEP if winner else START
34
+ bid = ask_bid(name, minimum)
35
+ if bid:
36
+ winner, price, changed = name, bid, True
37
+ print(f"目前最高:{winner}|{price} 幣")
38
+ if not changed or price >= BUDGET:
39
+ return winner, price
40
+
41
+
42
+ def announce(result):
43
+ winner, price = result
44
+ if not winner:
45
+ print("流標:沒有符合條件的出價。")
46
+ return
47
+ print(f"{winner} 得標|成交 {price} 幣|剩餘 {BUDGET - price} 幣")
48
+
49
+
50
+ def main():
51
+ if not 1 <= START <= BUDGET or STEP < 1:
52
+ print("請設定 1 ≤ 起標價 ≤ 預算,最低加價至少 1 幣。")
53
+ return
54
+ print(f"\n荒謬商品拍賣會|{PRODUCT}")
55
+ print(f"每人 {BUDGET} 枚虛擬幣|起標 {START}|公開加價至少 {STEP} 幣")
56
+ print("輸入 0 代表這次不加價;一整輪沒人加價即開標。")
57
+ announce(open_round(PLAYERS))
58
+
59
+
60
+ if __name__ == "__main__":
61
+ main()
classroom_data/templates/week24/README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Lesson 24|公開與秘密出價
2
+
3
+ 這個專題不需要之前的作品或資料。執行 `main.py`,只用虛擬幣,不使用真錢。
4
+
5
+ - 玩法:秘密出價先用紙條,全部決定後再由主持人代輸入。程式不會把輸入框當保密工具。
6
+ - 今天做:同一商品、同一預算、同一批買家,各玩一輪。先預測哪一輪成交價高,再看結果。
7
+ - 交給同學測:測試秘密出價平手與流標。輪流對調兩種玩法的順序,避免把熟悉程度當成規則效果。
8
+
9
+ L23–25 共用這個拍賣工作區。已經改過程式的同學,先暫存再取用別週範例;匯入整份套版會替換目前工作副本。也可以沿用原稿,只參考下一週的函式。
classroom_data/templates/week24/main.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """荒謬商品拍賣會:使用虛擬幣,所有資料只留在本次執行。"""
2
+
3
+ PRODUCT = "永遠慢一天的作業提醒手錶"
4
+ BUDGET = 100
5
+ START = 10
6
+ STEP = 5
7
+ PLAYERS = ["甲", "乙", "丙"]
8
+ BOTS = [("模擬買家甲", 30), ("模擬買家乙", 45), ("模擬買家丙", 60)]
9
+
10
+
11
+ def ask_bid(name, minimum, sealed=False):
12
+ if minimum > BUDGET:
13
+ return 0
14
+ while True:
15
+ prompt = "秘密出價" if sealed else "出價"
16
+ raw = input(f"{name},{prompt} {minimum}~{BUDGET} 幣,0 放棄:").strip()
17
+ try:
18
+ bid = int(raw)
19
+ except ValueError:
20
+ print("請輸入整數。")
21
+ continue
22
+ if bid == 0 or minimum <= bid <= BUDGET:
23
+ return bid
24
+ print(f"出價需在 {minimum}~{BUDGET} 幣之間。")
25
+
26
+
27
+ def open_round(players, solo=False):
28
+ """每次新出價都公開;全員一整輪沒有加價即開標。"""
29
+ winner, price = "", 0
30
+ while True:
31
+ changed = False
32
+ for name in players:
33
+ if name == winner:
34
+ continue
35
+ minimum = price + STEP if winner else START
36
+ bid = ask_bid(name, minimum)
37
+ if bid:
38
+ winner, price, changed = name, bid, True
39
+ print(f"目前最高:{winner}|{price} 幣")
40
+ if solo:
41
+ for bot, cap in BOTS:
42
+ minimum = price + STEP if winner else START
43
+ if bot != winner and minimum <= min(cap, BUDGET):
44
+ winner, price, changed = bot, minimum, True
45
+ print(f"{bot} 公開出價:{price} 幣")
46
+ if not changed or price >= BUDGET:
47
+ return winner, price
48
+
49
+
50
+ def sealed_round(players, solo=False):
51
+ """每人一次;同價依收件順序。現場以紙條先寫好再輸入。"""
52
+ offers = []
53
+ print("先各自寫好出價,再由主持人輸入;開標前不要讓其他人看 Console。")
54
+ for name in players:
55
+ bid = ask_bid(name, START, sealed=True)
56
+ if bid:
57
+ offers.append((name, bid))
58
+ if solo:
59
+ offers.extend((name, cap) for name, cap in BOTS if START <= cap <= BUDGET)
60
+ return max(offers, key=lambda offer: offer[1], default=("", 0))
61
+
62
+
63
+ def announce(result):
64
+ winner, price = result
65
+ if not winner:
66
+ print("流標:沒有符合條件的出價。")
67
+ return
68
+ print(f"{winner} 得標|成交 {price} 幣|剩餘 {BUDGET - price} 幣")
69
+
70
+
71
+ def compare(sealed, opened):
72
+ print("\n成交價比較(共同尺度:每格 5 幣,數字是實際價格)")
73
+ for label, (winner, price) in [("秘密出價", sealed), ("公開出價", opened)]:
74
+ print(f"{label}|{'█' * (price // 5)} {price} 幣" if winner else f"{label}|流標")
75
+ print("想一想:看到別人出價時,你有改變原本的決定嗎?")
76
+
77
+
78
+ def main():
79
+ if not 1 <= START <= BUDGET or STEP < 1:
80
+ print("請設定 1 ≤ 起標價 ≤ 預算,最低加價至少 1 幣。")
81
+ return
82
+ print(f"\n荒謬商品拍賣會|{PRODUCT}")
83
+ print(f"每人 {BUDGET} 枚虛擬幣|起標 {START}|公開加價至少 {STEP} 幣")
84
+ print("所有人都可以放棄。相同價格的秘密出價,以先收到的為準。")
85
+ sealed = sealed_round(PLAYERS)
86
+ announce(sealed)
87
+ print("\n公開出價開始:每位買家的預算重新計算。")
88
+ opened = open_round(PLAYERS)
89
+ announce(opened)
90
+ compare(sealed, opened)
91
+
92
+
93
+ if __name__ == "__main__":
94
+ main()
classroom_data/templates/week25/README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lesson 25|三分鐘家長展示
2
+
3
+ 這個專題不需要之前的作品或資料。執行 `main.py`,只用虛擬幣,不使用真錢。
4
+
5
+ - 玩法:這份 Console 版有三位模擬買家,適合先自己排練;家長版另有可點選的網頁。
6
+ - 今天做:用同一件商品跑兩種玩法,換成自己的商品或測試一條規則,準備講解一個 if。
7
+ - 交給同學測:說明模擬買家的出價是程式規則,不是真人資料;一次展示不能證明某種規則一定賣更貴。
8
+
9
+ 網頁試玩:把 `網頁版.html.txt` 的內容存成 `index.html`,在瀏覽器開啟。先改商品名稱及描述;熟練後再改 JavaScript 裡 `bots` 的出價上限。網頁可離線執行,不用連接 Python 或設定伺服器。
10
+
11
+ L23–25 共用這個拍賣工作區。已經改過程式的同學,先暫存再取用別週範例;匯入整份套版會替換目前工作副本。也可以沿用原稿,只參考下一週的函式。
classroom_data/templates/week25/main.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """荒謬商品拍賣會:使用虛擬幣,所有資料只留在本次執行。"""
2
+
3
+ PRODUCT = "永遠慢一天的作業提醒手錶"
4
+ BUDGET = 100
5
+ START = 10
6
+ STEP = 5
7
+ PLAYERS = ["甲", "乙", "丙"]
8
+ BOTS = [("模擬買家甲", 30), ("模擬買家乙", 45), ("模擬買家丙", 60)]
9
+
10
+
11
+ def ask_bid(name, minimum, sealed=False):
12
+ if minimum > BUDGET:
13
+ return 0
14
+ while True:
15
+ prompt = "秘密出價" if sealed else "出價"
16
+ raw = input(f"{name},{prompt} {minimum}~{BUDGET} 幣,0 放棄:").strip()
17
+ try:
18
+ bid = int(raw)
19
+ except ValueError:
20
+ print("請輸入整數。")
21
+ continue
22
+ if bid == 0 or minimum <= bid <= BUDGET:
23
+ return bid
24
+ print(f"出價需在 {minimum}~{BUDGET} 幣之間。")
25
+
26
+
27
+ def open_round(players, solo=False):
28
+ """每次新出價都公開;全員一整輪沒有加價即開標。"""
29
+ winner, price = "", 0
30
+ while True:
31
+ changed = False
32
+ for name in players:
33
+ if name == winner:
34
+ continue
35
+ minimum = price + STEP if winner else START
36
+ bid = ask_bid(name, minimum)
37
+ if bid:
38
+ winner, price, changed = name, bid, True
39
+ print(f"目前最高:{winner}|{price} 幣")
40
+ if solo:
41
+ for bot, cap in BOTS:
42
+ minimum = price + STEP if winner else START
43
+ if bot != winner and minimum <= min(cap, BUDGET):
44
+ winner, price, changed = bot, minimum, True
45
+ print(f"{bot} 公開出價:{price} 幣")
46
+ if not changed or price >= BUDGET:
47
+ return winner, price
48
+
49
+
50
+ def sealed_round(players, solo=False):
51
+ """每人一次;同價依收件順序。現場以紙條先寫好再輸入。"""
52
+ offers = []
53
+ if solo:
54
+ print("你先決定一次出價;輸入後才開標。")
55
+ else:
56
+ print("先各自寫好出價,再由主持人輸入;開標前不要讓其他人看 Console。")
57
+ for name in players:
58
+ bid = ask_bid(name, START, sealed=True)
59
+ if bid:
60
+ offers.append((name, bid))
61
+ if solo:
62
+ offers.extend((name, min(cap, BUDGET)) for name, cap in BOTS if cap >= START)
63
+ return max(offers, key=lambda offer: offer[1], default=("", 0))
64
+
65
+
66
+ def announce(result):
67
+ winner, price = result
68
+ if not winner:
69
+ print("流標:沒有符合條件的出價。")
70
+ return
71
+ print(f"{winner} 得標|成交 {price} 幣|剩餘 {BUDGET - price} 幣")
72
+
73
+
74
+ def compare(sealed, opened):
75
+ print("\n成交價比較(共同尺度:每格 5 幣,數字是實際價格)")
76
+ for label, (winner, price) in [("秘密出價", sealed), ("公開出價", opened)]:
77
+ print(f"{label}|{'█' * (price // 5)} {price} 幣" if winner else f"{label}|流標")
78
+ print("想一想:看到別人出價時,你有改變原本的決定嗎?")
79
+
80
+
81
+ def main():
82
+ if not 1 <= START <= BUDGET or STEP < 1:
83
+ print("請設定 1 ≤ 起標價 ≤ 預算,最低加價至少 1 幣。")
84
+ return
85
+ print(f"\n荒謬商品拍賣會|{PRODUCT}")
86
+ print(f"每人 {BUDGET} 枚虛擬幣|起標 {START}|公開加價至少 {STEP} 幣")
87
+ print("所有人都可以放棄。相同價格的秘密出價,以先收到的為準。")
88
+ sealed = sealed_round(["你"], solo=True)
89
+ announce(sealed)
90
+ print("\n公開出價開始:你的預算重新計算。")
91
+ opened = open_round(["你"], solo=True)
92
+ announce(opened)
93
+ compare(sealed, opened)
94
+
95
+
96
+ if __name__ == "__main__":
97
+ main()
classroom_data/templates/week25/網頁版.html.txt ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="zh-Hant">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>荒謬商品拍賣會</title>
7
+ <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%23163f39'/%3E%3Cpath fill='%23dcf08e' d='M6 21h20v5H6zM10 8h12v9H10z'/%3E%3C/svg%3E">
8
+ <style>
9
+ :root{color-scheme:light;--paper:#edf3ef;--ink:#152d29;--muted:#3e5853;--stage:#163f39;--lime:#dcf08e;--line:#a9bcb6;--rust:#913d25}
10
+ *{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font:1rem/1.65 system-ui,sans-serif}
11
+ main{width:min(68rem,100% - 2rem);margin:clamp(1rem,5vw,4rem) auto 2rem}
12
+ h1,h2,p{margin:0}h1{font-size:clamp(2rem,5vw,4rem);line-height:1.13;letter-spacing:-.03em}
13
+ h2{font-size:1.4rem;margin-bottom:.45rem}.intro{margin:.85rem 0 1.4rem;color:var(--muted);max-width:66ch}
14
+ .board{display:grid;grid-template-columns:1fr 1fr;border:1px solid var(--line);border-radius:16px;overflow:hidden;background:#fff}
15
+ .lot{background:var(--stage);color:#fff;padding:clamp(1.25rem,4vw,2.75rem);display:flex;flex-direction:column;justify-content:space-between;gap:1rem}
16
+ .lot h2{font-size:clamp(1.6rem,3.5vw,2.6rem);line-height:1.18;max-width:13em;margin-bottom:.6rem}
17
+ .rules{display:flex;gap:1rem;flex-wrap:wrap;margin:0}.rules dt{font-size:.85rem;color:#fff}.rules dd{margin:0;font-weight:700;font-size:1.25rem;font-variant-numeric:tabular-nums}
18
+ .play{padding:clamp(1.2rem,4vw,2.5rem);min-width:0}.explain{color:var(--muted);min-height:3.3em}
19
+ form{margin:1.2rem 0 .55rem}label{display:block;font-weight:650;margin-bottom:.3rem}
20
+ .controls,.actions{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center}
21
+ input,button{font:inherit;border-radius:8px;min-height:44px}input{width:7rem;border:1px solid #647c74;padding:.4rem .6rem;color:var(--ink)}
22
+ button{padding:.45rem .9rem;background:var(--stage);border:1px solid var(--stage);color:#fff;font-weight:650;cursor:pointer}
23
+ button.secondary{background:#fff;color:var(--stage)}button:hover{filter:brightness(.91)}
24
+ :focus-visible{outline:3px solid var(--rust);outline-offset:3px}::selection{background:var(--lime);color:var(--ink)}
25
+ #status{margin:.65rem 0;min-height:1.7em;font-weight:600}#status.error{color:var(--rust)}
26
+ #history{padding-left:1.3rem;margin:.4rem 0;color:var(--muted);max-height:8rem;overflow:auto}
27
+ #comparison{margin:1.5rem 0}.result{display:grid;grid-template-columns:6em minmax(0,1fr) 5em;gap:.6rem;align-items:center;margin:.5rem 0}
28
+ .track{height:1rem;background:#d1ddd8;border-radius:4px;overflow:hidden}.bar{display:block;height:100%;background:var(--stage);width:0}.result:nth-of-type(2) .bar{background:var(--rust)}
29
+ .note{margin-top:1.1rem;color:var(--muted);max-width:67ch}#reset{margin-top:1rem}[hidden]{display:none!important}
30
+ @media(max-width:650px){.board{grid-template-columns:1fr}.lot{gap:.65rem}.explain{min-height:0}}
31
+ </style>
32
+ </head>
33
+ <body>
34
+ <main>
35
+ <h1>荒謬商品拍賣會</h1>
36
+ <p class="intro">用 100 枚虛擬幣,和三位模擬買家競標。同一件商品玩兩輪,看看能不能用不同的價格買到。</p>
37
+ <div class="board">
38
+ <section class="lot" aria-labelledby="item">
39
+ <div><h2 id="item">永遠慢一天的作業提醒手錶</h2><p>提醒非常準時,只是準時在截止日的隔天。</p></div>
40
+ <dl class="rules"><div><dt>每輪預算</dt><dd>100 幣</dd></div><div><dt>起標</dt><dd>10 幣</dd></div><div><dt>公開加價</dt><dd>至少 5 幣</dd></div></dl>
41
+ </section>
42
+ <section class="play" aria-labelledby="round">
43
+ <h2 id="round" tabindex="-1">第一輪:秘密出價</h2>
44
+ <p class="explain" id="explain">你只能出價一次,送出後才看到其他買家的出價。</p>
45
+ <form id="bid-form" novalidate>
46
+ <label for="bid" id="bid-label">你的出價(10~100 幣)</label>
47
+ <div class="controls"><input id="bid" type="number" inputmode="numeric" min="10" max="100" step="1" aria-describedby="status"><button id="bid-button">送出並開標</button></div>
48
+ </form>
49
+ <div class="actions"><button class="secondary" id="pass" type="button">不出價</button><button id="next" type="button" hidden>開始公開出價</button></div>
50
+ <p id="status" role="status" aria-live="polite"></p>
51
+ <ol id="history" aria-label="已公開的出價紀錄" hidden></ol>
52
+ </section>
53
+ </div>
54
+ <section id="comparison" aria-labelledby="result-title" hidden>
55
+ <h2 id="result-title" tabindex="-1">兩輪成交價</h2>
56
+ <div class="result"><span>秘密出價</span><div class="track" aria-hidden="true"><span class="bar" id="sealed-bar"></span></div><strong id="sealed-price"></strong></div>
57
+ <div class="result"><span>公開出價</span><div class="track" aria-hidden="true"><span class="bar" id="open-bar"></span></div><strong id="open-price"></strong></div>
58
+ <p class="note">兩條長條以 100 幣為滿格。看到別人出價後,你有沒有改變願意出的價格?</p>
59
+ <button class="secondary" id="reset" type="button" hidden>重新體驗</button>
60
+ </section>
61
+ <p class="note">模擬買家兩輪使用相同預算上限,公開時只按最低加價,秘密時一次出到自己的上限。同價的秘密出價由先收到者得標。這是規則示範,不是真人實驗結果;不收集姓名或儲存出價。</p>
62
+ </main>
63
+ <script>
64
+ "use strict";
65
+ // L25 練習:換商品文字、調整模擬買家的上限,預測並實際試玩。
66
+ const BUDGET=100, START=10, STEP=5;
67
+ const bots=[["模擬買家甲",30],["模擬買家乙",45],["模擬買家丙",60]];
68
+ const $=id=>document.getElementById(id);
69
+ let phase="sealed", leader="", price=0, sealedPrice=0;
70
+ const form=$("bid-form"), bid=$("bid"), history=$("history"), status=$("status");
71
+ function message(text,error=false){status.textContent=text;status.classList.toggle("error",error);if(error)bid.setAttribute("aria-invalid","true");else bid.removeAttribute("aria-invalid");}
72
+ function log(text){const row=document.createElement("li");row.textContent=text;history.append(row);history.hidden=false;history.scrollTop=history.scrollHeight;}
73
+ function minimum(){return phase==="sealed"||!leader?START:price+STEP;}
74
+ function refresh(){
75
+ const min=minimum();
76
+ form.hidden=min>BUDGET;
77
+ bid.min=min;bid.max=BUDGET;bid.value="";
78
+ $("bid-label").textContent="你的出價("+min+"~"+BUDGET+" 幣)";
79
+ }
80
+ function sealed(value){
81
+ const offers=[...(value?[["你",value]]:[]),...bots.filter(([,cap])=>cap>=START).map(([name,cap])=>[name,Math.min(cap,BUDGET)])];
82
+ offers.forEach(([name,amount])=>log(name+":"+amount+" 幣"));
83
+ const winner=offers.reduce((best,offer)=>offer[1]>best[1]?offer:best,["",0]);
84
+ sealedPrice=winner[1];phase="between";
85
+ form.hidden=true;$("pass").hidden=true;$("next").hidden=false;
86
+ message(winner[0]?winner[0]+"得標,成交 "+sealedPrice+" 幣。":"本輪流標。");$("next").focus();
87
+ }
88
+ function botTurns(){
89
+ let raised=true;
90
+ while(raised){
91
+ raised=false;
92
+ for(const [name,cap] of bots){
93
+ const min=minimum();
94
+ if(leader!==name&&min<=Math.min(cap,BUDGET)){leader=name;price=min;raised=true;log(name+" 出價 "+price+" 幣");}
95
+ }
96
+ }
97
+ }
98
+ function open(){
99
+ phase="open";leader="";price=0;history.replaceChildren();history.hidden=true;
100
+ $("round").textContent="第二輪:公開出價";
101
+ $("explain").textContent="預算重新給你 100 幣。你可以看到目前最高價,每次出價後模擬買家也能再加。";
102
+ $("next").hidden=true;$("pass").hidden=false;$("pass").textContent="結束競標";
103
+ $("bid-button").textContent="公開加價";
104
+ botTurns();refresh();message(leader?"目前最高:"+leader+","+price+" 幣。":"目前尚無出價。");$("round").focus();
105
+ }
106
+ function close(){
107
+ phase="done";form.hidden=true;$("pass").hidden=true;$("reset").hidden=false;
108
+ $("explain").textContent="兩輪都已完成,下方可以比較成交價。";
109
+ message(leader?leader+"得標,成交 "+price+" 幣。":"本輪流標。");
110
+ [["sealed",sealedPrice],["open",price]].forEach(([mode,value])=>{
111
+ $(mode+"-price").textContent=value?value+" 幣":"流標";
112
+ $(mode+"-bar").style.width=(value/BUDGET*100)+"%";
113
+ });
114
+ $("comparison").hidden=false;$("result-title").focus();
115
+ }
116
+ form.addEventListener("submit",event=>{
117
+ event.preventDefault();
118
+ if(!["sealed","open"].includes(phase))return;
119
+ const value=Number(bid.value),min=minimum();
120
+ if(!bid.value.trim()||!Number.isInteger(value)||value<min||value>BUDGET){
121
+ message("請輸入 "+min+"~"+BUDGET+" 之間的整數。",true);bid.focus();return;
122
+ }
123
+ if(phase==="sealed"){sealed(value);return;}
124
+ leader="你";price=value;log("你出價 "+price+" 幣");botTurns();refresh();
125
+ message("目前最高:"+leader+","+price+" 幣。"+(minimum()>BUDGET?"已沒有可用的加價額度,可以結束競標。":""));
126
+ if(form.hidden)$("pass").focus();else bid.focus();
127
+ });
128
+ $("pass").addEventListener("click",()=>{if(phase==="sealed")sealed(0);else if(phase==="open")close();});
129
+ $("next").addEventListener("click",open);
130
+ $("reset").addEventListener("click",()=>{
131
+ phase="sealed";leader="";price=sealedPrice=0;history.replaceChildren();history.hidden=true;
132
+ $("round").textContent="第一輪:秘密出價";$("explain").textContent="你只能出價一次,送出後才看到其他買家的出價。";
133
+ $("comparison").hidden=true;$("reset").hidden=true;$("pass").hidden=false;$("pass").textContent="不出價";$("bid-button").textContent="送出並開標";
134
+ refresh();message("");bid.focus();
135
+ });
136
+ </script>
137
+ </body>
138
+ </html>
projects/DEMO/展示用學生/荒謬商品拍賣會/index.html ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="zh-Hant">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>荒謬商品拍賣會</title>
7
+ <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%23163f39'/%3E%3Cpath fill='%23dcf08e' d='M6 21h20v5H6zM10 8h12v9H10z'/%3E%3C/svg%3E">
8
+ <style>
9
+ :root{color-scheme:light;--paper:#edf3ef;--ink:#152d29;--muted:#3e5853;--stage:#163f39;--lime:#dcf08e;--line:#a9bcb6;--rust:#913d25}
10
+ *{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font:1rem/1.65 system-ui,sans-serif}
11
+ main{width:min(68rem,100% - 2rem);margin:clamp(1rem,5vw,4rem) auto 2rem}
12
+ h1,h2,p{margin:0}h1{font-size:clamp(2rem,5vw,4rem);line-height:1.13;letter-spacing:-.03em}
13
+ h2{font-size:1.4rem;margin-bottom:.45rem}.intro{margin:.85rem 0 1.4rem;color:var(--muted);max-width:66ch}
14
+ .board{display:grid;grid-template-columns:1fr 1fr;border:1px solid var(--line);border-radius:16px;overflow:hidden;background:#fff}
15
+ .lot{background:var(--stage);color:#fff;padding:clamp(1.25rem,4vw,2.75rem);display:flex;flex-direction:column;justify-content:space-between;gap:1rem}
16
+ .lot h2{font-size:clamp(1.6rem,3.5vw,2.6rem);line-height:1.18;max-width:13em;margin-bottom:.6rem}
17
+ .rules{display:flex;gap:1rem;flex-wrap:wrap;margin:0}.rules dt{font-size:.85rem;color:#fff}.rules dd{margin:0;font-weight:700;font-size:1.25rem;font-variant-numeric:tabular-nums}
18
+ .play{padding:clamp(1.2rem,4vw,2.5rem);min-width:0}.explain{color:var(--muted);min-height:3.3em}
19
+ form{margin:1.2rem 0 .55rem}label{display:block;font-weight:650;margin-bottom:.3rem}
20
+ .controls,.actions{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center}
21
+ input,button{font:inherit;border-radius:8px;min-height:44px}input{width:7rem;border:1px solid #647c74;padding:.4rem .6rem;color:var(--ink)}
22
+ button{padding:.45rem .9rem;background:var(--stage);border:1px solid var(--stage);color:#fff;font-weight:650;cursor:pointer}
23
+ button.secondary{background:#fff;color:var(--stage)}button:hover{filter:brightness(.91)}
24
+ :focus-visible{outline:3px solid var(--rust);outline-offset:3px}::selection{background:var(--lime);color:var(--ink)}
25
+ #status{margin:.65rem 0;min-height:1.7em;font-weight:600}#status.error{color:var(--rust)}
26
+ #history{padding-left:1.3rem;margin:.4rem 0;color:var(--muted);max-height:8rem;overflow:auto}
27
+ #comparison{margin:1.5rem 0}.result{display:grid;grid-template-columns:6em minmax(0,1fr) 5em;gap:.6rem;align-items:center;margin:.5rem 0}
28
+ .track{height:1rem;background:#d1ddd8;border-radius:4px;overflow:hidden}.bar{display:block;height:100%;background:var(--stage);width:0}.result:nth-of-type(2) .bar{background:var(--rust)}
29
+ .note{margin-top:1.1rem;color:var(--muted);max-width:67ch}#reset{margin-top:1rem}[hidden]{display:none!important}
30
+ @media(max-width:650px){.board{grid-template-columns:1fr}.lot{gap:.65rem}.explain{min-height:0}}
31
+ </style>
32
+ </head>
33
+ <body>
34
+ <main>
35
+ <h1>荒謬商品拍賣會</h1>
36
+ <p class="intro">用 100 枚虛擬幣,和三位模擬買家競標。同一件商品玩兩輪,看看能不能用不同的價格買到。</p>
37
+ <div class="board">
38
+ <section class="lot" aria-labelledby="item">
39
+ <div><h2 id="item">永遠慢一天的作業提醒手錶</h2><p>提醒非常準時,只是準時在截止日的隔天。</p></div>
40
+ <dl class="rules"><div><dt>每輪預算</dt><dd>100 幣</dd></div><div><dt>起標</dt><dd>10 幣</dd></div><div><dt>公開加價</dt><dd>至少 5 幣</dd></div></dl>
41
+ </section>
42
+ <section class="play" aria-labelledby="round">
43
+ <h2 id="round" tabindex="-1">第一輪:秘密出價</h2>
44
+ <p class="explain" id="explain">你只能出價一次,送出後才看到其他買家的出價。</p>
45
+ <form id="bid-form" novalidate>
46
+ <label for="bid" id="bid-label">你的出價(10~100 幣)</label>
47
+ <div class="controls"><input id="bid" type="number" inputmode="numeric" min="10" max="100" step="1" aria-describedby="status"><button id="bid-button">送出並開標</button></div>
48
+ </form>
49
+ <div class="actions"><button class="secondary" id="pass" type="button">不出價</button><button id="next" type="button" hidden>開始公開出價</button></div>
50
+ <p id="status" role="status" aria-live="polite"></p>
51
+ <ol id="history" aria-label="已公開的出價紀錄" hidden></ol>
52
+ </section>
53
+ </div>
54
+ <section id="comparison" aria-labelledby="result-title" hidden>
55
+ <h2 id="result-title" tabindex="-1">兩輪成交價</h2>
56
+ <div class="result"><span>秘密出價</span><div class="track" aria-hidden="true"><span class="bar" id="sealed-bar"></span></div><strong id="sealed-price"></strong></div>
57
+ <div class="result"><span>公開出價</span><div class="track" aria-hidden="true"><span class="bar" id="open-bar"></span></div><strong id="open-price"></strong></div>
58
+ <p class="note">兩條長條以 100 幣為滿格。看到別人出價後,你有沒有改變願意出的價格?</p>
59
+ <button class="secondary" id="reset" type="button" hidden>重新體驗</button>
60
+ </section>
61
+ <p class="note">模擬買家兩輪使用相同預算上限,公開時只按最低加價,秘密時一次出到自己的上限。同價的秘密出價由先收到者得標。這是規則示範,不是真人實驗結果;不收集姓名或儲存出價。</p>
62
+ </main>
63
+ <script>
64
+ "use strict";
65
+ // L25 練習:換商品文字、調整模擬買家的上限,預測並實際試玩。
66
+ const BUDGET=100, START=10, STEP=5;
67
+ const bots=[["模擬買家甲",30],["模擬買家乙",45],["模擬買家丙",60]];
68
+ const $=id=>document.getElementById(id);
69
+ let phase="sealed", leader="", price=0, sealedPrice=0;
70
+ const form=$("bid-form"), bid=$("bid"), history=$("history"), status=$("status");
71
+ function message(text,error=false){status.textContent=text;status.classList.toggle("error",error);if(error)bid.setAttribute("aria-invalid","true");else bid.removeAttribute("aria-invalid");}
72
+ function log(text){const row=document.createElement("li");row.textContent=text;history.append(row);history.hidden=false;history.scrollTop=history.scrollHeight;}
73
+ function minimum(){return phase==="sealed"||!leader?START:price+STEP;}
74
+ function refresh(){
75
+ const min=minimum();
76
+ form.hidden=min>BUDGET;
77
+ bid.min=min;bid.max=BUDGET;bid.value="";
78
+ $("bid-label").textContent="你的出價("+min+"~"+BUDGET+" 幣)";
79
+ }
80
+ function sealed(value){
81
+ const offers=[...(value?[["你",value]]:[]),...bots.filter(([,cap])=>cap>=START).map(([name,cap])=>[name,Math.min(cap,BUDGET)])];
82
+ offers.forEach(([name,amount])=>log(name+":"+amount+" 幣"));
83
+ const winner=offers.reduce((best,offer)=>offer[1]>best[1]?offer:best,["",0]);
84
+ sealedPrice=winner[1];phase="between";
85
+ form.hidden=true;$("pass").hidden=true;$("next").hidden=false;
86
+ message(winner[0]?winner[0]+"得標,成交 "+sealedPrice+" 幣。":"本輪流標。");$("next").focus();
87
+ }
88
+ function botTurns(){
89
+ let raised=true;
90
+ while(raised){
91
+ raised=false;
92
+ for(const [name,cap] of bots){
93
+ const min=minimum();
94
+ if(leader!==name&&min<=Math.min(cap,BUDGET)){leader=name;price=min;raised=true;log(name+" 出價 "+price+" 幣");}
95
+ }
96
+ }
97
+ }
98
+ function open(){
99
+ phase="open";leader="";price=0;history.replaceChildren();history.hidden=true;
100
+ $("round").textContent="第二輪:公開出價";
101
+ $("explain").textContent="預算重新給你 100 幣。你可以看到目前最高價,每次出價後模擬買家也能再加。";
102
+ $("next").hidden=true;$("pass").hidden=false;$("pass").textContent="結束競標";
103
+ $("bid-button").textContent="公開加價";
104
+ botTurns();refresh();message(leader?"目前最高:"+leader+","+price+" 幣。":"目前尚無出價。");$("round").focus();
105
+ }
106
+ function close(){
107
+ phase="done";form.hidden=true;$("pass").hidden=true;$("reset").hidden=false;
108
+ $("explain").textContent="兩輪都已完成,下方可以比較成交價。";
109
+ message(leader?leader+"得標,成交 "+price+" 幣。":"本輪流標。");
110
+ [["sealed",sealedPrice],["open",price]].forEach(([mode,value])=>{
111
+ $(mode+"-price").textContent=value?value+" 幣":"流標";
112
+ $(mode+"-bar").style.width=(value/BUDGET*100)+"%";
113
+ });
114
+ $("comparison").hidden=false;$("result-title").focus();
115
+ }
116
+ form.addEventListener("submit",event=>{
117
+ event.preventDefault();
118
+ if(!["sealed","open"].includes(phase))return;
119
+ const value=Number(bid.value),min=minimum();
120
+ if(!bid.value.trim()||!Number.isInteger(value)||value<min||value>BUDGET){
121
+ message("請輸入 "+min+"~"+BUDGET+" 之間的整數。",true);bid.focus();return;
122
+ }
123
+ if(phase==="sealed"){sealed(value);return;}
124
+ leader="你";price=value;log("你出價 "+price+" 幣");botTurns();refresh();
125
+ message("目前最高:"+leader+","+price+" 幣。"+(minimum()>BUDGET?"已沒有可用的加價額度,可以結束競標。":""));
126
+ if(form.hidden)$("pass").focus();else bid.focus();
127
+ });
128
+ $("pass").addEventListener("click",()=>{if(phase==="sealed")sealed(0);else if(phase==="open")close();});
129
+ $("next").addEventListener("click",open);
130
+ $("reset").addEventListener("click",()=>{
131
+ phase="sealed";leader="";price=sealedPrice=0;history.replaceChildren();history.hidden=true;
132
+ $("round").textContent="第一輪:秘密出價";$("explain").textContent="你只能出價一次,送出後才看到其他買家的出價。";
133
+ $("comparison").hidden=true;$("reset").hidden=true;$("pass").hidden=false;$("pass").textContent="不出價";$("bid-button").textContent="送出並開標";
134
+ refresh();message("");bid.focus();
135
+ });
136
+ </script>
137
+ </body>
138
+ </html>