object oriented – Robot OOP Class in Python

Hello everyone!

Here is the thing. So I wanted at first to create Robot class, I want him to move around some board. Maybe 10×10 or something like that, then i wanted to invent a Robot fights class, I want to add class players (becuase i want to play between player 1 and player 2) but here it is what I have so much.

Lets focus on this code because I want it to make it much better then start to create robot fights!

class Robot:

    def __init__(self, name, place, start = (0,0), power = 9):
        self.name = name
        self.start = start
        self.place = place
        self.power = power
    def get_name(self):
        return self.name
    def get_start(self):
        return self.start
    def get_place(self):
        return self.place
    def get_power(self):
        return self.power

    def set_name(self, x):
        if isinstance(x, str):
            self.name = x
            raise TypeError("must be a string")
    def set_start(self, x):
        if isinstance(x, tuple):
            self.start = x
            raise TypeError("must be a tuple")
    def set_place(self, x):
        if isinstance(x, list):
            self.place = x
            raise TypeError("must be a list")
    def set_power(self, x):
        if isinstance(x, int):
            self.power = x
            raise TypeError("must a int")
    def check_power(self):
        if self.power <= 0:
            raise ValueError("No power")
    def left(self, value):
        self.power -= value

        if self.place(0) - value < 0:
            self.place(0) = self.place(0) - value + 8

            self.place(0) = self.place(0) - value
    def up(self, value):
        self.power -= value

        if self.place(1) + value > 7:
            self.place(1) = self.place(1) + value - 8

            self.place(1) = self.place(1) + value

        if self.place(1) == 5:
            self.power += 2

    def __str__(self):
        return self.name, self.place, self.power

Also want I want to make better in this one. Well power will be important in the Robot fights, because if some robot from player 1 will be near to robot from player 2 I want them to you know, fight, so the power will be pretty good right there, if they will be near to each other the power will decrease until the robot is destroyed. But lets focus on above code to make it better.

Any tips how to make this SHORTER and more neat, closer to a advanced or just better solution will be definitely on point.

Have a great day!

c# – Should Source Generators be used as a replacement for class libraries

You’re mixing a few concepts here.

You’ve got class wrappers, you’ve got code generators, you’ve got build-on-deploy. The solution you’re talking about works if you can safely build the application per deployment, which is a big assumption.

A different architectural approach might be to making your Logging feature an interface, and allowing any all implementations of that interface, and perhaps scanning for implementations of that interface at runtime.

Here’s an example of how you might make that work using Reflection:


In terms of deployment, you’re saying something like “This app logs to anything that implements IMyLog, so if you want logging to work make sure you drop a DLL in the runtime directory that has an IMyLog in it.”

My point is that you seem to be solving a deployment problem with a complicated workaround that might force you to compile the application individually for each installation. I’m suggesting that you consider solving the deployment problem at the point of deployment instead.

Can’t find Payment Date in the Payment or Order class

I’m working to an extension that needs to push to an external service every order and refund that happens on the shop. One of the needed infos it needs to pass is the payment date – and for the life of me I can’t find it, neither in the payment class nor in the order class:

Does someone know how to retrieve this information?
Shippings and Orders have the getCreatedAt() method, but I don’t find it for Payments, nor do I find anything similar, though it occurs to me as a basic info that should be available.

Thanks everyone!

nt.number theory – Construction of Genus class fields

Given a finite extension $K/mathbb{Q}$, the genus class field $G$ is defined to be the maximal abelian extension of $mathbb{Q}$ that is a subfield of the Hilbert class field $H$ of $K$. I am trying to understand the proof of an alternative construction of $G$ in the case when $K$ is a cyclic extension with prime degree $l$ as follows.

Let $p_1, p_2, …, p_n$ be the primes in $mathbb{Q}$ that ramify in $K$. Suppose $G_1, G_2, …, G_n$ be cyclic extensions of degree $l$ over $mathbb{Q}$ such that $G_i$ ramify only at $p_i$. Then $G = G_1 G_2…G_n$.

I was reading the proof in “Construction of Class Fields – Cael Herz“. The basic strategy is to associate $K$ and the $G_i$‘s to norm subgroups of $K$ using Class field theory and relate them. But I find it hard to comprehend and justify certain crucial claims in the proof one of which I posted on MO earlier (Norm groups of number fields).

Can someone refer me to an alternate proof of this fact or provide some light into Cael’s proof if possible?

dnd 4e – What happens when a race skill and a class skill is the same?

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

dnd 4e – What happens when a race skill and a class skill is the same in D&D 4th edition?

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

java – Dyanamic class load for server side application

Is there a problem to use reflection (specifically class.forName) in server side application?

My main thread about this is someone to inject a code dumping memory in JVM and adding commands in reference memory field, but this is unlike in server side (and if server side was compromised this will be a minor problem).

Btw, I am asking because static analises keep acusing as a vulnerabiliy

php – Should my class “data” dependency be a repository, adapter or another pattern?

I have a class called CheckUserUltraSecretInformation that is kind of a Use Case in “clean architecture terms”, this class has a dependency that is responsible for retrieving a couple of information from a cache “provider”, such as Redis, this is a crucial business rule for this use case, in order for the user to retrieve its “ultra-secret information” the cached information must exist.

since “retrieving the data from the cache” it’s a data layer, my first thought was to use the repository pattern, but that implicates that I also have an Entity or a “Domain Model” for this repository, the thing is: although I can picture a “CachedUserInformation” object and its properties I cannot see the CachedUserInformation as an entity, because it’s not a “core” object of my application.

I feel like this is more of a rule of the use case than an entity, but I cannot just return an array of data from this “repository”.

should I just call it CachedUserDataAdapter and return the CachedUserInformation object?

what are some good approaches for this scenario?

my code:

interface CachedUserDataRepository {
    function findByDocument(string $document): CachedUserInformation;

class CheckUserUltraSecretInformation {

    public function __construct(
        private CachedUserDataRepository $cachedDataRepository

    public function Check(string $document)
        $cachedUserData = $this->cachedDataRepository->findByDocument($document);

        if(empty($cachedUserData)) {
            throw new Exception('User Cached information not found, cannot proceed');

class CachedUserInformation {
    private string $id;
    private string $secretInformation;

design – Where to store the results of a class internal computation?

WI suspect the real problem here is that there exists a point in time when you know the instance vars but you haven’t yet done the expensive calculation to get the data. Which means if you store the data in the object it now has two states: before and after. Bleh.

I think it’s better to have an object that knows the logic and vars used to make the data but that shoves the data into a new object that it hands to whatever asked for it.

This way there isn’t two states. There’s just an object that makes the data object when asked. Done this way it can immutable. It’s ready to make the data when it exists. And the data object is ready to be used when it exists.

What’s really nice is you don’t have to ask things if they’re ready to be used because if they exist, they’re ready.

If the problem is that you need the data in contexts where you don’t remember if it’s already been created you can make things more efficient by caching the data.

But sometimes the best way to solve a problem is to avoid it. If you need the data then let something inject it into you. Don’t go asking for it.

design – What desing pattern / class / interface should I use for encapsulating a program?

I am building a chess – related application, and I want to use a pre-compiled program called Stockfish as my chess engine. I am wondering what is the best practice to encapsulate the usage of the program. There are many design patterns to match – Strategy, as the program is, after all, an algorithm that operate on some context (a.k.a the game position). Adapter, as what I essentially do is to provide an interface for a pre-existing program, Facade, as the engine is, in fact, an entire subsystem of the program, or even just a regular interface, that specifies all engine operations like this example, and more. Of course, every solution requires easy switch to another engine.

What is the best practice in this case?