-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleEPBotNative.vb
More file actions
658 lines (529 loc) · 30.3 KB
/
ModuleEPBotNative.vb
File metadata and controls
658 lines (529 loc) · 30.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
Imports System.Runtime.InteropServices
Imports System.Text
'''
''' Wrapper P/Invoke dla natywnej biblioteki AOT EPBot.dll (Windows x64).
''' Sygnatury zgodne z epbot.h.
'''
''' Konwencje z nagłówka:
''' - Stringi: UTF-8, null-terminated
''' - Wyjściowe stringi: caller-provided buffer + buffer_size
''' - Tablice stringów: newline-separated w jednym buforze
''' - Boolean: int (0=false, nonzero=true)
''' - handle: nieprzezroczysty wskaźnik z epbot_create()
'''
Module ModuleEPBotNative
Private Const DLL As String = "EPBot.dll"
Private Const BUF As Integer = 4096 ' rozmiar domyślnego bufora
' ── Błędy ────────────────────────────────────────────────────
Public Const EPBOT_OK As Integer = 0
Public Const EPBOT_ERR_NULL_HANDLE As Integer = -1
Public Const EPBOT_ERR_EXCEPTION As Integer = -2
Public Const EPBOT_ERR_BUFFER_SMALL As Integer = -3
' ════════════════════════════════════════════════════════════
' Surowe deklaracje P/Invoke
' ════════════════════════════════════════════════════════════
' ── Lifecycle ────────────────────────────────────────────────
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_create() As IntPtr
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Sub epbot_destroy(instance As IntPtr)
End Sub
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_last_error() As IntPtr ' const char* — nie zwalniać
End Function
' ── Core bidding ─────────────────────────────────────────────
' longer: karty jako "AKQJ\nT98\n765\n432" (C.D.H.S, newline-separated)
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_new_hand(instance As IntPtr,
player_position As Integer,
<MarshalAs(UnmanagedType.LPUTF8Str)> longer As String,
dealer As Integer,
vulnerability As Integer,
repeating As Integer,
b_playing As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_bid(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_bid(instance As IntPtr,
spare As Integer,
new_value As Integer,
<MarshalAs(UnmanagedType.LPUTF8Str)> str_alert As String) As Integer
End Function
' bids: odzywki newline-separated
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_arr_bids(instance As IntPtr,
<MarshalAs(UnmanagedType.LPUTF8Str)> bids As String) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_interpret_bid(instance As IntPtr, bid_code As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_ask(instance As IntPtr) As Integer
End Function
' ── Conventions ──────────────────────────────────────────────
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_conventions(instance As IntPtr,
site As Integer,
<MarshalAs(UnmanagedType.LPUTF8Str)> convention As String) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_conventions(instance As IntPtr,
site As Integer,
<MarshalAs(UnmanagedType.LPUTF8Str)> convention As String,
value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_system_type(instance As IntPtr, system_number As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_system_type(instance As IntPtr, system_number As Integer, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_opponent_type(instance As IntPtr, system_number As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_opponent_type(instance As IntPtr, system_number As Integer, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_convention_index(instance As IntPtr,
<MarshalAs(UnmanagedType.LPUTF8Str)> name As String) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_convention_name(instance As IntPtr, index As Integer,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_convention_name(instance As IntPtr, index As Integer,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_selected_conventions(instance As IntPtr,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_system_name(instance As IntPtr, system_number As Integer,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
' ── Scoring & settings ───────────────────────────────────────
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_scoring(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_scoring(instance As IntPtr, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_playing_skills(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_playing_skills(instance As IntPtr, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_defensive_skills(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_defensive_skills(instance As IntPtr, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_licence(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_licence(instance As IntPtr, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_bcalconsole_path(instance As IntPtr,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_bcalconsole_path(instance As IntPtr,
<MarshalAs(UnmanagedType.LPUTF8Str)> path As String) As Integer
End Function
' ── State queries ────────────────────────────────────────────
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_position(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_dealer(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_vulnerability(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_version(instance As IntPtr) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_copyright(instance As IntPtr,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_last_epbot_error(instance As IntPtr,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_str_bidding(instance As IntPtr,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
' ── Info / meaning ───────────────────────────────────────────
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_alerting(instance As IntPtr, k As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_info_alerting(instance As IntPtr, k As Integer, value As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_meaning(instance As IntPtr, k As Integer,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_info_meaning(instance As IntPtr, k As Integer,
<MarshalAs(UnmanagedType.LPUTF8Str)> value As String) As Integer
End Function
' ── Card play ────────────────────────────────────────────────
' arr_cards: karty dziadka newline-separated
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_dummy(instance As IntPtr,
dummy As Integer,
<MarshalAs(UnmanagedType.LPUTF8Str)> arr_cards As String,
all_data As Integer,
ByRef without_final_length As Byte) As Integer
End Function
' current_longers: 0 lub 1; wynik: newline-separated suits
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_arr_suits(instance As IntPtr,
current_longers As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_hand(instance As IntPtr,
player_position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_lead(instance As IntPtr,
force_lead As Integer,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_set_lead(instance As IntPtr,
<MarshalAs(UnmanagedType.LPUTF8Str)> played_card As String) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_cards(instance As IntPtr,
buffer As Byte(), buffer_size As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_probable_level(instance As IntPtr, strain As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_feature(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_min_length(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_max_length(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_probable_length(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_honors(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_suit_power(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_strength(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
<DllImport(DLL, CallingConvention:=CallingConvention.Cdecl)>
Private Function epbot_get_info_stoppers(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
End Function
' ════════════════════════════════════════════════════════════
' Pomocnicze
' ════════════════════════════════════════════════════════════
''' <summary>Odczytuje bufor bajtów UTF-8 jako String (do pierwszego \0).</summary>
Private Function BufToString(buf As Byte()) As String
Dim nul As Integer = Array.IndexOf(buf, CByte(0))
If nul < 0 Then nul = buf.Length
Return Encoding.UTF8.GetString(buf, 0, nul)
End Function
''' <summary>Konwertuje tablicę String() na jeden string newline-separated.</summary>
Private Function SuitsToLonger(suits As String()) As String
' suits(0)=C suits(1)=D suits(2)=H suits(3)=S
Return String.Join(vbLf, suits)
End Function
''' <summary>Pobiera ostatni błąd FFI jako String.</summary>
Public Function GetLastError() As String
Dim ptr As IntPtr = epbot_get_last_error()
If ptr = IntPtr.Zero Then Return String.Empty
Return Marshal.PtrToStringUTF8(ptr)
End Function
' ════════════════════════════════════════════════════════════
' Klasa opakowująca — identyczny interfejs jak EPBot8739.EPBot
' ════════════════════════════════════════════════════════════
''' <summary>
''' Wrapper natywnej biblioteki EPBot (AOT DLL) z interfejsem identycznym
''' jak EPBot8739.EPBot — pozostały kod projektu nie wymaga zmian.
''' </summary>
Public Class EPBot
Implements IDisposable
Private ReadOnly _h As IntPtr
Private _disposed As Boolean = False
Public Sub New()
_h = epbot_create()
If _h = IntPtr.Zero Then
Throw New InvalidOperationException(
"epbot_create() zwróciło null. Sprawdź czy EPBot.dll jest w katalogu exe.")
End If
End Sub
' ── Zarządzanie ręką ──────────────────────────────────────
''' <summary>
''' Inicjalizuje rękę gracza.
''' suits(): indeks 0=C, 1=D, 2=H, 3=S — zgodnie z C_CLUBS..C_SPADES.
''' </summary>
Public Sub new_hand(position As Integer, suits As String(),
dealer As Integer, vulnerable As Integer)
Dim longer As String = SuitsToLonger(suits)
Dim rc As Integer = epbot_new_hand(_h, position, longer, dealer, vulnerable, 0, 0)
CheckRc(rc, "epbot_new_hand")
End Sub
' ── Licytacja ─────────────────────────────────────────────
Public Function get_bid() As Integer
Dim rc As Integer = epbot_get_bid(_h)
If rc < 0 Then Throw New InvalidOperationException($"epbot_get_bid error {rc}: {GetLastError()}")
Return rc
End Function
''' <summary>Rozgłasza odzywkę (str_alert opcjonalny).</summary>
Public Sub set_bid(position As Integer, bid As Integer,
Optional alert As String = "")
Dim rc As Integer = epbot_set_bid(_h, position, bid, If(alert, ""))
CheckRc(rc, "epbot_set_bid")
End Sub
''' <summary>Ustawia pełną historię licytacji z tablicy arr_bids.</summary>
Public Sub set_arr_bids(bids As String())
Dim filled As New System.Collections.Generic.List(Of String)
For Each b As String In bids
If String.IsNullOrEmpty(b) Then Exit For
filled.Add(Left(b, 2)) ' tylko kod numeryczny, bez alertu
Next
Dim rc As Integer = epbot_set_arr_bids(_h, String.Join(vbLf, filled))
CheckRc(rc, "epbot_set_arr_bids")
End Sub
' ── Rozgrywka ─────────────────────────────────────────────
''' <summary>Ustawia dziadka i jego karty.</summary>
Public Sub set_dummy(dummy As Integer, suits As String())
Dim longer As String = SuitsToLonger(suits)
Dim wfl As Byte = 0
Dim rc As Integer = epbot_set_dummy(_h, dummy, longer, 0, wfl)
CheckRc(rc, "epbot_set_dummy")
End Sub
''' <summary>
''' Zwraca tablicę stringów (karty wszystkich graczy) jako newline-separated,
''' zgodnie z układem EPBot8739: 4 graczy × 4 kolory.
''' </summary>
Public Function get_arr_suits() As String()
Dim outBuf(BUF - 1) As Byte
Dim count As Integer = 0
Dim rc As Integer = epbot_get_arr_suits(_h, 0, outBuf, BUF, count)
CheckRc(rc, "epbot_get_arr_suits")
Return BufToString(outBuf).Split(vbLf)
End Function
' ── Informacje o odzywce ──────────────────────────────────
Public Function info_alerting(position As Integer) As Boolean
Return epbot_get_info_alerting(_h, position) <> 0
End Function
Public Function info_meaning(position As Integer) As String
Dim outBuf(BUF - 1) As Byte
Dim rc As Integer = epbot_get_info_meaning(_h, position, outBuf, BUF)
If rc < 0 Then Return String.Empty
Return BufToString(outBuf)
End Function
Public Function get_str_bidding() As String
Dim outBuf(BUF - 1) As Byte
Dim rc As Integer = epbot_get_str_bidding(_h, outBuf, BUF)
If rc < 0 Then Return String.Empty
Return BufToString(outBuf)
End Function
Public Function interpret_bid(bid_code As Integer) As Integer
Return epbot_interpret_bid(_h, bid_code)
End Function
Public Function ask() As Integer
Return epbot_ask(_h)
End Function
Public ReadOnly Property LastError As String
Get
Return get_last_epbot_error()
End Get
End Property
' ── State queries ─────────────────────────────────────────
Public Function get_position() As Integer
Return epbot_get_position(_h)
End Function
Public Function get_dealer() As Integer
Return epbot_get_dealer(_h)
End Function
Public Function get_vulnerability() As Integer
Return epbot_get_vulnerability(_h)
End Function
Public Function get_last_epbot_error() As String
Dim outBuf(511) As Byte
Dim rc As Integer = epbot_get_last_epbot_error(_h, outBuf, 512)
If rc < 0 Then Return String.Empty
Return BufToString(outBuf)
End Function
' ── Analiza ───────────────────────────────────────────────
Public Function get_probable_level(strain As Integer) As Integer
Return epbot_get_probable_level(_h, strain)
End Function
' ── Card play ─────────────────────────────────────────────
Public Function get_lead(force_lead As Boolean) As String
Dim outBuf(255) As Byte
Dim rc As Integer = epbot_get_lead(_h, If(force_lead, 1, 0), outBuf, 256)
If rc < 0 Then Return String.Empty
Return BufToString(outBuf)
End Function
Public Sub set_lead(played_card As String)
CheckRc(epbot_set_lead(_h, played_card), "epbot_set_lead")
End Sub
Public Function get_cards() As String
Dim outBuf(BUF - 1) As Byte
Dim rc As Integer = epbot_get_cards(_h, outBuf, BUF)
If rc < 0 Then Return String.Empty
Return BufToString(outBuf)
End Function
Public Function get_hand(player_position As Integer) As String()
Dim outBuf(BUF - 1) As Byte
Dim count As Integer = 0
Dim rc As Integer = epbot_get_hand(_h, player_position, outBuf, BUF, count)
If rc < 0 Then Return New String() {}
Return BufToString(outBuf).Split(vbLf)
End Function
' ── Info arrays ───────────────────────────────────────────
Public Function info_feature(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_feature)
End Function
Public Function info_min_length(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_min_length)
End Function
Public Function info_max_length(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_max_length)
End Function
Public Function info_probable_length(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_probable_length)
End Function
Public Function info_honors(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_honors)
End Function
Public Function info_suit_power(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_suit_power)
End Function
Public Function info_strength(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_strength)
End Function
Public Function info_stoppers(position As Integer) As Integer()
Return GetInfoIntArray(position, AddressOf epbot_get_info_stoppers)
End Function
' helper dla int-array getterów
Private Delegate Function InfoIntArrayFunc(instance As IntPtr, position As Integer,
buffer As Byte(), buffer_size As Integer,
ByRef count_out As Integer) As Integer
Private Function GetInfoIntArray(position As Integer, fn As InfoIntArrayFunc) As Integer()
Dim rawBuf(BUF - 1) As Byte
Dim count As Integer = 0
Dim rc As Integer = fn(_h, position, rawBuf, BUF, count)
If rc < 0 OrElse count = 0 Then Return New Integer() {}
Dim result(count - 1) As Integer
System.Buffer.BlockCopy(rawBuf, 0, result, 0, count * 4)
Return result
End Function
' ── Właściwości systemu ───────────────────────────────────
''' <summary>Typ systemu licytacyjnego (0=NS, 1=WE): T_21GF, T_SAYC itd.</summary>
Public Property system_type(team As Integer) As Integer
Get
Return epbot_get_system_type(_h, team)
End Get
Set(value As Integer)
CheckRc(epbot_set_system_type(_h, team, value), "epbot_set_system_type")
End Set
End Property
''' <summary>Sposób punktacji: 0=MP, 1=IMP.</summary>
Public Property scoring As Integer
Get
Return epbot_get_scoring(_h)
End Get
Set(value As Integer)
CheckRc(epbot_set_scoring(_h, value), "epbot_set_scoring")
End Set
End Property
''' <summary>Konwencja dla danego zespołu i nazwy.</summary>
Public Property conventions(team As Integer, name As String) As Integer
Get
Return epbot_get_conventions(_h, team, name)
End Get
Set(value As Integer)
CheckRc(epbot_set_conventions(_h, team, name, value), "epbot_set_conventions")
End Set
End Property
' ── Info ─────────────────────────────────────────────────
Public ReadOnly Property Version As Integer
Get
Return epbot_version(_h)
End Get
End Property
Public ReadOnly Property Copyright As String
Get
Dim outBuf(511) As Byte
epbot_copyright(_h, outBuf, 512)
Return BufToString(outBuf)
End Get
End Property
' ── Obsługa błędów ────────────────────────────────────────
Private Sub CheckRc(rc As Integer, name As String)
If rc < 0 Then
Dim detail As String = String.Empty
Dim ebuf(511) As Byte
If epbot_get_last_epbot_error(_h, ebuf, 512) >= 0 Then
detail = BufToString(ebuf)
End If
If String.IsNullOrEmpty(detail) Then detail = GetLastError()
Throw New InvalidOperationException($"{name} zwróciło {rc}: {detail}")
End If
End Sub
' ── IDisposable ───────────────────────────────────────────
Protected Overridable Sub Dispose(disposing As Boolean)
If Not _disposed Then
epbot_destroy(_h)
_disposed = True
End If
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
Dispose(False)
MyBase.Finalize()
End Sub
End Class
End Module