476
4
submitted 2 years ago* (last edited 2 years ago) by 0WN3D@lemmy.cafe to c/programming@lemmy.ml

I'm planning on creating an AI tournament as a project to test out some of the potential AI performance in a game, eg tic-tac-toe.

I'd like the AI to know the full history of a game instead of the instantaneous game-state because I might want some AI that use the historical data, eg AI that always put in the opposite cell of it's previous move if possible.

The question I am wondering is, what is the best way to setup the tournament.

I have a few options in my headspace:

  1. Write everything in Rust (since I also am semi-interested in getting experience with the language)
  2. Write everything in Python
  3. Write the AI's in anything I want, but interact using stdin/stdout. Connect the AI using some shell script.

There are a few nice things I want to have:

  1. able to run AI ad hoc against each other, or easily modify the tourney. ie I might want to add a new AI that runs against each of the previous AI instead of having the re-run the whole tourney
    • Rust would require a re-compile of the tourney code each time which may not be convenient
    • Options 2 and 3 would be much more convenient since it wouldn't require a full compilation and I can easily write a throwaway script
  2. be able to run it in a somewhat performant way since I might want to simulate many rounds
    • Rust AI would be fast, but to avoid the issue in (1), I might go with solution 3 with the underlying AI being in Rust. But I'm not sure how significant the speed of piping IO between programs compare to if I had wrote everything as a Python program

Any advice on this would be great, cause there might be some options that I might have omitted.

477
9
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
478
2
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
479
7
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
480
3
submitted 2 years ago by JRepin@lemmy.ml to c/programming@lemmy.ml

With this step, we are opening Qt SVG up to support elements beyond SVG Tiny 1.2. This means that we will aim to include useful and common elements from SVG 1.1 and SVG 2.0, if maintenance is reasonably feasible. We will not aim for compliance with these standards but we will keep an eye on feature requests from our users. Further, we are open to contributions of such extensions by the community. So if you miss your favorite SVG element in the list above, fell free to send us some code, preferably on our code review platform.

481
3
How to Build an Origami Computer (www.quantamagazine.org)
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
482
6
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
483
5
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
484
13
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
485
26
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
486
17
submitted 2 years ago by Fudoshin@feddit.uk to c/programming@lemmy.ml

I fancy learning a new language. I've got experience in Python, PHP, Ruby, Bash and many years ago Java, Haskell and C++. Though I'm absolute dogshit at system languages generally. I GET pointers but I fucking hate having to think about them.

Is Nim nice? Is it better than Rust? I like being a contrarian so I'd rather not learn Rust since it's too fashionable right now. But Nim seems to have that independent, cool streak but still niche. It also seems a little bit like Python but with low level stuff slapped in.

I fancy doing something like some of the following:

  • TUI/ncurses pacman app.
  • Taskade terminal app.
  • Network scanning tool.
  • USB midi tool.
  • Kitchen sink that gargles my balls (optional)

So how is Nim for this? Thoughts? Feelings?

487
6
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
488
2
submitted 2 years ago by trevor@lemmy.ml to c/programming@lemmy.ml

etk is a library for the Ebitengine game engine that simplifies creating graphical user interfaces. The README lists the features and widgets. Boxcars uses etk to greatly simplify UI development, as its single codebase targets web, desktop and Android.

489
8
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
490
3
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
491
3
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
492
12
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml

ffplay -f lavfi -i life=s=400x300:mold=10:r=30:ratio=0.1:death_color=#C83232:life_color=#00ff00,scale=1200:800:flags=32

493
3
(a.a)
submitted 2 years ago* (last edited 2 years ago) by velox_vulnus@lemmy.ml to c/programming@lemmy.ml

Here's the entire program

heron.c

#include <stdlib.h>
#include <stdio.h>

/* lower and upper iteration limits centered around 1.0 */
static double const eps1m01 = 1.0 - 0x1P-01;
static double const eps1p01 = 1.0 + 0x1P-01;
static double const eps1m24 = 1.0 - 0x1P-24;
static double const eps1p24 = 1.0 + 0x1P-24;

int main (int argc, char* argv[argc + 1]) {
    for (int i = 1; i < argc; ++i) {            // process args
        double const a = strtod(argv[i], 0);    // arg -> double
        double x = 1.0;
        for (;;) {                              // by powers of 2
            double prod = a * x;
            if (prod < eps1m01) {
                x *= 2.0;
            } else if (eps1p01 < prod) {
                x *= 0.5;
            } else {
                break;
            }
        }
        for (;;) {                              // Heron approximation
            double prod = a * x;
            if ((prod < eps1m24) || (eps1p24 < prod)) {
                x *= (2.0 - prod);
            } else {
                break;
            }
        }
        printf("heron: a=%.5e, \tx=%.5e, \ta*x=%.12f\n",
            a, x, a * x);
    }
    return EXIT_SUCCESS;
}

Here's how it spits out the answer:

output

$ heron 0.07 5 6E+23
heron: a=7.00000e-02, 	x=1.42857e+01, 	a*x=0.999999999996
heron: a=5.00000e+00, 	x=2.00000e-01, 	a*x=0.999999999767
heron: a=6.00000e+23, 	x=1.66667e-24, 	a*x=0.999999997028

I'm not able to understand a few things, like for example:

  • why char* argv[argc + 1]? Why not char** argv[argc] or simply char** argv?
  • why the need for eps1m01, eps1p01, eps1m24 or eps1p24? What kind of optimization does it add to this program?
494
3
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
495
10
(lemmy.ml)
submitted 2 years ago* (last edited 2 years ago) by velox_vulnus@lemmy.ml to c/programming@lemmy.ml

From what I'm able to understand:

  • declaration is when prototype or declaration is used to describe the features
  • definition is when a declaration is also assigned a literal or an object, such that a chunk of memory is allocated
  • initialization is the assignment of an object, either during definition or immediately after declaration
  • assignment is the setting of a value of a particular object at any stage of the program execution

Which of the follow terms overlap? Which of them is a superset/subset of each other?

496
7
submitted 2 years ago* (last edited 2 years ago) by 0WN3D@lemmy.cafe to c/programming@lemmy.ml

I had this discussion in my workplace and wanted to share and get opinions from the folks here. (I suspect StackOverflow might not appreciate such open ended questions).

Context: We have a microservice involved in pricing signalling to our users. We have an endpoint which have the following:

  • Input: an array of item ID's
  • Output: the expected final price of the given items.

The item prices are quite volatile (and no, it is not crypto related), and is dependent on things like instantaneous supply-demand, promotions, etc.

Since the prices change quite frequently, it became a requirement that we commit to the price that was shown to the user initially, up to a certain time period (eg 5 min after the price was calculated). This improves the UX since the user will be charged as according to what they expected at the start.

Currently, in our system, we achieve this via a JWT, which contains all the details in the request, the obligatory signature, and the expiry set to 5 min from the time it was generated.

After generating this receipt, the FE can then call the endpoint with the JWT which does the actual payment processing using the params encoded in the token. This way, we know that the params + the total cost that is quoted in the JWT originates from our service since we verify that we signed it.

And the system evolves once more. We see that in the system, there is this mechanism, that if the token is expired, we do not reject the request at the charging step. Instead, we call the price endpoint internally using the params provided, and check if the price is the same as in the expired JWT. If it is the same, we process it as normal despite the JWT being expired.

This is where the contention lies. I believe that we should force the user to procure another non-expired JWT and removing this complex logic while others believe in the value of this improved UX where the user doesn't need to restart the whole flow again.

What do y'all think? Which way would y'all architect the endpoint? Or is there something fundamentally wrong with our design (maybe JWT is not the best suited for this use case)?

497
-4
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
498
1
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
499
5
It’s All Bullshit (thebaffler.com)
submitted 2 years ago by yogthos@lemmy.ml to c/programming@lemmy.ml
500
22

If you use a compiled language, you should periodically look at Godbolt and see what your code is doing and what changes to your code will do in the compiled output.

In this case a positively insane way of calculating squares and cubes generates 311 lines of ARM assembler output that will swallow your memory. With even something as simple as -O1 on the command line it's replaced by one or two multiplications respectively. With -fwhole-program it removes the functions entirely and interlaces them into the loop in main().

Know your tools. It makes huge differences!

view more: ‹ prev next ›

General Programming Discussion

10013 readers
8 users here now

A general programming discussion community.

Rules:

  1. Be civil.
  2. Please start discussions that spark conversation

Other communities

Systems

Functional Programming

Also related

founded 7 years ago
MODERATORS