Best Python code snippet using autotest_python
game_master.py
Source: game_master.py
1import random2from solutions.exercises.ch2.ex36.bear import Bear3from solutions.exercises.ch2.ex36.fish import Fish4class GameMaster:5 _board: list6 _fish: int7 _bears: int8 _remaining: list[int]9 def __init__(self, size: int, fish: int, bears: int):10 self._board = [None] * size11 self._fish = fish12 self._bears = bears13 self._remaining = [i for i in range(len(self._board))]14 def _setup_board(self):15 """Initialize board before a game."""16 fish = self._fish17 bears = self._bears18 while fish > 0 or bears > 0:19 rand = random.choice(self._remaining)20 self._remaining.remove(rand)21 if fish > 0:22 self._board[rand] = Fish()23 fish -= 124 else:25 self._board[rand] = Bear()26 bears -= 127 self._show_board()28 def _teardown_board(self):29 """Teardown the board after a game."""30 for i in range(len(self._board)):31 if self._board[i] is not None:32 self._board[i] = None33 self._remaining = [i for i in range(len(self._board))]34 def __str__(self):35 result = ["|"] * (2 * len(self._board) + 1)36 for i in range(len(self._board)):37 result[2*i + 1] = " " if self._board[i] is None else self._board[i].__str__()38 return " ".join(result)39 def _show_board(self):40 """Print the current state of the board."""41 print(self)42 def officiate_game(self):43 """Run the simulation."""44 self._setup_board()45 fish = self._fish46 bears = self._bears47 while fish > 0 and bears > 0:48 for i in range(len(self._board)):49 curr = self._board[i]50 if curr is not None:51 move = curr.make_move()52 if move == 0 or i + move < 0 or i + move == len(self._board):53 continue54 else:55 other = self._board[i + move]56 if type(curr) == type(other):57 if len(self._remaining) > 0:58 j = random.choice(self._remaining)59 self._remaining.remove(j)60 self._board[j] = type(curr)()61 if type(curr) == Fish:62 fish += 163 else:64 bears += 165 else:66 if type(curr) == Bear or other is None:67 self._board[i + move] = curr68 self._board[i] = None69 self._remaining.append(i)70 if other is not None:71 fish -= 172 else:73 self._remaining.remove(i + move)74 self._show_board()...
bitbuffer.py
Source: bitbuffer.py
1from __future__ import annotations2from typing import BinaryIO, TYPE_CHECKING3if TYPE_CHECKING:4 from dissect.cstruct.types import RawType5class BitBuffer:6 """Implements a bit buffer that can read and write bit fields."""7 def __init__(self, stream: BinaryIO, endian: str):8 self.stream = stream9 self.endian = endian10 self._type = None11 self._buffer = 012 self._remaining = 013 def read(self, field_type: RawType, bits: int) -> int:14 if self._remaining == 0 or self._type != field_type:15 self._type = field_type16 self._remaining = field_type.size * 817 self._buffer = field_type._read(self.stream)18 if bits > self._remaining:19 raise ValueError("Reading straddled bits is unsupported")20 if self.endian != ">":21 v = self._buffer & ((1 << bits) - 1)22 self._buffer >>= bits23 self._remaining -= bits24 else:25 v = self._buffer & (((1 << (self._remaining - bits)) - 1) ^ ((1 << self._remaining) - 1))26 v >>= self._remaining - bits27 self._remaining -= bits28 return v29 def write(self, field_type: RawType, data: int, bits: int) -> None:30 if self._remaining == 0 or self._type != field_type:31 if self._type:32 self.flush()33 self._remaining = field_type.size * 834 self._type = field_type35 if self.endian != ">":36 self._buffer |= data << (self._type.size * 8 - self._remaining)37 else:38 self._buffer |= data << (self._remaining - bits)39 self._remaining -= bits40 if self._remaining == 0:41 self.flush()42 def flush(self) -> None:43 self._type._write(self.stream, self._buffer)44 self._type = None45 self._remaining = 046 self._buffer = 047 def reset(self) -> None:48 self._type = None49 self._buffer = 0...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!