質問するログイン新規登録

回答編集履歴

1

追記

2025/10/19 17:26

投稿

melian
melian

スコア21527

answer CHANGED
@@ -29,16 +29,44 @@
29
29
  line 15, x=27, len=1
30
30
  Assertion failed: i > 1 || ch != MAX_UNICODE, file ../pdcurses/refresh.c, line 174
31
31
  ```
32
+ ----
33
+ アサーションエラーなので、アサーションを無効にしてPDCursesをビルドして試してみました。具体的には以下のリポジトリからPDCursesの最新版をcloneして、gccのスイッチオプションに`-DNDEBUG`を追加してコンパイルします。
32
34
 
33
- ところで、デバッグの途中で気がついたのですが、カーソルを非表示にすると上記のエラーが発生しません。詳細については時間が取れれば調べますが、まずはこれで動作を確認してみてください。
35
+  [Bill-Gray/PDCursesMod: Public Domain Curses - a curses library for environments that don't fit the termcap/terminfo model, modified and extended from the 'official' version](https://github.com/Bill-Gray/PDCursesMod)
34
36
 
35
- **shougi_main.c**
37
+ ビルドしたpdcurses.dllをリンクして実行してみるとアサーションエラー以外のエラーは発生せずに以下の画像の様に表示されます。(飛車に移動してエンターキーを押した直後) 画像の左側は全角スペース(U+3000:IDEOGRAPHIC SPACE)、右側は□(U+25a1:WHITE SQUARE)でマスクしています。右側のWHITE SQUAREの方が判りやすいと思いますが、後手の「桂」、「角」、「歩」の部分が表示されています。これはWHITE SQUAREのフォント幅が半角のためで(フォントはConsolas)、元の"v"(U+0076)の部分にだけ表示されているためです。
38
+
39
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2025-10-20/6c2a9415-3a3e-4bb5-b476-2663e6296140.png)
40
+ **shougi_highlight.c:highlight_moves()**
36
41
  ```c
37
- int main(void) {
42
+ attron(COLOR_PAIR(4));
43
+ // 左側の画像
44
+ mvaddstr(ORIGIN_Y + ny * CELL_H, ORIGIN_X + nx * CELL_W, " ");
45
+ // 右側の画像
46
+ // mvaddstr(ORIGIN_Y + ny * CELL_H, ORIGIN_X + nx * CELL_W, "□");
47
+ attroff(COLOR_PAIR(4));
38
- :
48
+ ```
39
49
 
40
- noecho();
50
+ おそらく、PDCursesのソースコードにワイド文字を考慮していないアサーションがあるためではないかと推測しています。
51
+
41
- cbreak();
52
+ なお、PDCursesにおける「文字」の扱いは以下に記載されています。
53
+
54
+  [PDCursesMod/curses.h at master · Bill-Gray/PDCursesMod](https://github.com/Bill-Gray/PDCursesMod/blob/master/curses.h#L417)
55
+
42
- keypad(stdscr, TRUE);
56
+ > Text Attributes
43
- curs_set(0); // カーソルを非表示にする
57
+ > \===============
58
+ >
59
+ > By default, PDCursesMod uses 64-bit integers for its chtype. All chtypes have bits devoted to character data, attribute data, and color pair data. There are three configurations supported :
60
+ >
61
+ > Default, 64-bit chtype, **both wide- and 8-bit character builds**:
62
+ >
44
- ```
63
+ >```
64
+ > color pair | unused | modifiers | character eg 'a'
65
+ > --------------|--------|-----------------|--------------------
66
+ > 63 62 .. 45 44|43 .. 39|37 36 35 .. 22 21|20 19 18 .. 3 2 1 0
67
+ > ```
68
+ > 21 character bits (0-20), **enough for full Unicode coverage**
69
+ > 17 attribute bits (21-37)
70
+ > 6 currently unused bits (38-43)
71
+ > 20 color pair bits (44-63), enough for 1048576 color pairs
72
+