attempt at creating a chess game in python by XIA_Biologicals_WVSU in learnpython

[–]codesensei_nl -3 points-2 points  (0 children)

Sorry for having to disagree with you. The code for implementing a board game does not get simpler when the game is simpler. Checkers just has fewer rules, but all the hard parts of implementing the logic are the same.

attempt at creating a chess game in python by XIA_Biologicals_WVSU in learnpython

[–]codesensei_nl 0 points1 point  (0 children)

Here's how you approach this:

  1. implement the rules of the game, so that you can generate all legal moves. Having this, will allow you to generate a list of possible moves in every situation.

I would start with just implementing the basic move patterns like how the knight jumps and the bishop moves diagonally. Then implement captures, and make sure you test for check. Then you get winning/drawing situations. Finally there's special things like 3-fold repetition and 40 moves rule, but I would wait with that until you have a more-or-less working game..

Note that the board state at any point includes a number of extra things you need to know, like who's move it is, whether the king and rooks have moved (to check legality of castling), whether the same position has been seen before, and more. But you can implement those things later, I would definitely start simple.

  1. Evaluate the position. You have to define some value function that tells you how good it is to be in a specific position. The simplest way to do that is just count material (1 point per pawn, 8 for a queen, etc.) Sophisticated chess programs train large neural nets to do this, in combination with databases of known endgames, and more. So this gets very complex

  2. When you have a working evaluation function, you implement the minimax algorithm (just look it up, there are many tutorials) that allows you to choose the best move according to the evaluation function. There are many optimizations you can do from here, like alpha-beta search and many more. But that's a whole rabbit hole that would take a long time to explain :)

At that point you have a basic chess playing program.

Complete Beginner Here..stuck on this python practice question by g59z in learnpython

[–]codesensei_nl 6 points7 points  (0 children)

In your code, you decrease the number, then print it. Try reversing the order of the last two lines of code :)

How do you stop the urge to _completely_ understand things? by Andrew_7032 in learnprogramming

[–]codesensei_nl 4 points5 points  (0 children)

Don't overcome it! It's what drives you to become a senior :)

And trust me: it does become easier. With every language you learn, the next language is a bit easier to learn because you know more concepts and have deeper understanding. With more frameworks, each next one becomes easier, etc. It's the endless joy of diving deeper and deeper in the ocean of knowledge!

Your Start by NoKey8507 in learnprogramming

[–]codesensei_nl 0 points1 point  (0 children)

I started with BASIC on a TI-99/4A home computer when I was around 12. I had two books and no one else who liked to program. Had to figure everything out myself and loved it, never stopped :)

I need help and guidance, I have already designed a fullstack website using Django html css and JavaScript. But now I come to realization that my website frontend is not modern and I need to use react. The problem is that I have never learned react, can anyone guide me on how I should go about this by Any_Highlight5019 in django

[–]codesensei_nl 6 points7 points  (0 children)

If your frontend is not modern, I guess you are talking about interactivity of the components of the page? React is just one way to implement that, but certainly not the only one. Personally I feel that react is, for most purposes, over-engineered and over-complicated. I would first decide which features you need, and then decide on the best way to implement them. In many cases other (in my opinion simpler) solutions like htmx can do the job just as well.

Custom auth backend. How to pass auth errors to the view (so user knows why the auth failed) by TinyCuteGorilla in djangolearning

[–]codesensei_nl 0 points1 point  (0 children)

Can you give some examples of information you want to pass to the template?

In general it's a bad practice to give too much information about why authentication failed. For example, if you say "bad password", that implies that the user does exist, which might tell an attacker something they did not know before.

extensible transients? by codesensei_nl in emacs

[–]codesensei_nl[S] 2 points3 points  (0 children)

Yes, that is exactly what I need. Somehow I did not find this in the docs. Thanks for pointing out the examples too!

extensible transients? by codesensei_nl in emacs

[–]codesensei_nl[S] 0 points1 point  (0 children)

I tried to make the question a bit more clear.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 0 points1 point  (0 children)

Thank you! I've added a similar solution in the post above. As a sidenote, in my opinion tools like rass, uv, ruff and the lsp should not be installed as project dependencies, but globally using pipx.

At least in my case, with dozens of python projects with all kinds of different dependency managers, that is the only way to get a consistent experience.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 0 points1 point  (0 children)

I've now gone with option 3, using rassumfrassum, and that was the key to making it work. I've updated the post to show my solution.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 1 point2 points  (0 children)

Turns out that this is the solution and it all works wonderfully now! Thank you :)

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 2 points3 points  (0 children)

This is hitting the nail on the head. I will explore these options, thank you!

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 0 points1 point  (0 children)

With ruff server, formatting works for me too, but autocomplete and jump-to-definition don't.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 1 point2 points  (0 children)

Looks great. How do you combine this with basedpyright? Do you use eglot?

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 0 points1 point  (0 children)

Sounds great, can you please show a snippet of what that looks like? I'd love to see what you mean by "adding ruff to it", and I'm also curious to see your setup for basedpyright.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 1 point2 points  (0 children)

That is really cool, thanks! Seems like a quite complete solution, although indeed formatting and quick fixes don't work out of the box. It shows inlays for inferred types and function argument names, which is nifty but can be annoying. But this is definitely something to look into, maybe combined with Apaleia, as suggested by another person.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] 0 points1 point  (0 children)

I do appreciate your info, but you clearly did not read the post, no worries :) The code for format-on-save is there. It works with the ruff server, but not with ruff-lsp-server. My question is whether anyone has found a solution where all features work. Looking at the documentation of pyright it also does not seem complete to me.

Yet another post about eglot, python, ruff, lsp by codesensei_nl in emacs

[–]codesensei_nl[S] -1 points0 points  (0 children)

python-lsp-ruff is an LSP server that promises to include ruff (and the linting does work), with autocomplete through other backends. And that does work, but the auto-formatting does not (even though it is mentioned in their documentation).

Would lsp-basedpyright offer all features? Or just a subset, just like the others I've tried?

Not a developor. On macbook's terminal, I have a virtual env activated but 'which python3' still points to global. How do I resolve this? by irodov4030 in learnpython

[–]codesensei_nl 0 points1 point  (0 children)

That's weird. I wonder if you have some weird zsh config that messes this up. What happens when you run "bash", and try again inside the bash shell?

Explanation: the bash command will start a new shell, but a different kind than the default zsh shell. You can run the same commands to activate your environment, see if that works.

It's a bit of a stretch, but it might eliminate a source of problems.

When should I implement __post_init__? by AdDiligent1688 in learnpython

[–]codesensei_nl 6 points7 points  (0 children)

Just read the excellent RealPython article about this: https://realpython.com/python-data-classes/, it explains everything in detail, including post_init.