mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 12:11:33 -06:00
MultiServer: Allow games with no locations, add checks to pure python implementation. (#1944)
* Server: allow games with no locations again * Server: validate locations in pure python implementation and rework tests * Server: fix tests for py<3.11
This commit is contained in:
@@ -8,6 +8,7 @@ This is deliberately .pyx because using a non-compiled "pure python" may be slow
|
||||
|
||||
# pip install cython cymem
|
||||
import cython
|
||||
import warnings
|
||||
from cpython cimport PyObject
|
||||
from typing import Any, Dict, Iterable, Iterator, Generator, Sequence, Tuple, TypeVar, Union, Set, List, TYPE_CHECKING
|
||||
from cymem.cymem cimport Pool
|
||||
@@ -107,13 +108,16 @@ cdef class LocationStore:
|
||||
count += 1
|
||||
sender_count += 1
|
||||
|
||||
if not count:
|
||||
raise ValueError("No locations")
|
||||
if not sender_count:
|
||||
raise ValueError(f"Rejecting game with 0 players")
|
||||
|
||||
if sender_count != max_sender:
|
||||
# we assume player 0 will never have locations
|
||||
raise ValueError("Player IDs not continuous")
|
||||
|
||||
if not count:
|
||||
warnings.warn("Game has no locations")
|
||||
|
||||
# allocate the arrays and invalidate index (0xff...)
|
||||
self.entries = <LocationEntry*>self._mem.alloc(count, sizeof(LocationEntry))
|
||||
self.sender_index = <IndexEntry*>self._mem.alloc(max_sender + 1, sizeof(IndexEntry))
|
||||
@@ -140,9 +144,9 @@ cdef class LocationStore:
|
||||
self._proxies.append(None) # player 0
|
||||
assert self.sender_index[0].count == 0
|
||||
for i in range(1, max_sender + 1):
|
||||
if self.sender_index[i].count == 0 and self.sender_index[i].start >= count:
|
||||
self.sender_index[i].start = 0 # do not point outside valid entries
|
||||
assert self.sender_index[i].start < count
|
||||
assert self.sender_index[i].count == 0 or (
|
||||
self.sender_index[i].start < count and
|
||||
self.sender_index[i].start + self.sender_index[i].count <= count)
|
||||
key = i # allocate python integer
|
||||
proxy = PlayerLocationProxy(self, i)
|
||||
self._keys.append(key)
|
||||
|
Reference in New Issue
Block a user