Open Aldruun opened 1 year ago
Yes this is part of what I want to add next, thanks!
That's awesome! I would like to donate my personal chess board sounds for your cause and really don't want any credit, as I cut them from a cc0 (totally free) audio file from freesound.org and edited them in Audacity to get rid of annoying parts. I use them in GUIs that allow for sound customization.
Here is a link so you can have a listen and download. https://drive.google.com/drive/folders/1N-3DeR3vANZ6H4OQCWQ5QCaFwUpUIwHL?usp=sharing
Anyway, if you need help with sound design, I'd be glad to help.
Thank you. I have added sounds to most chess moves. The audio is now also changeable under "Customization", where the drop down shows default and your audio files.
Cc0 is very good in case more people are interested. Right now all is copied from chess.com since this is mostly a personal project and for friends :). If that will be the case, then I will redo the images in order to comply with cc of chess.com. Next I will add sliding pieces.
Once again thanks for your contribution, if there are features that you think could be nice, I will look into it!
That was fast! Excellent work! Now that I know what board actions can have audio I might design and upload the remaining sounds for my set and let you know.
As for suggestions,
I have an idea, probably for somewhere in the far future. In Fritz GUI there is this game mode where the player can earn imaginary cash, which motivates to play focused and adds a bit of excitement. Before a match the player chooses the amount of "money" that he will lose or win. This alone could be an interesting feature. During the match the engine and the player can double the amount when they think that they can win. But this would probably be too much for Nibbler and what it represents.
That is very interesting, but you are correct, this sounds like a feature for the future. After I implement my own initial ideas and optimize the ui / performance I will gladly look into some additional features as the one you mentioned. Thanks!
A solid plan. :-) BTW, If you need a German translator, let me know. I would be happy to help.
Here is another cute and relaxing sound theme that I recorded with a DAW during a few matches on CC "Nature" sound theme. Would fit a green board quite well. :-)
Just in case you want to add even more media, here is the Lichess Github repository. It includes most of the Lichess sound themes and piece graphics.
Thank you! When I have some time I will add some of that audio and graphical themes to allow more customization. As to sliding pieces, they are now implemented. It is looking good on my laptop and I didn't notice any graphical glitches when testing it. If you notice anything, I'm happy to fix it.
Perfect! Though the sounds are being played as soon as the pieces start moving. May be there is some sort of "OnPieceArrived" event that could start the sound? The sliding really puts some energy on the board!
Which gives me another idea for your "may be" TODO list: I haven't seen this yet on a 2D chess board, but as a former Unity game coder I swear that adding an arc to the sliding movement makes it look even more alive. I implemented this in a 2D game where creature sprites were boringly sliding around. After adding "hopping" it looked amazing! If you need easy to read C# snippets, I still have a few functions ready (max 2-10 lines) that you could refactor to Java.
Another cool thing would be an option for increased thinking time range for the engine to make it act more human-like. Plus the time it needs to calculate, to randomize it a bit.
Thank you. For any sliding piece the timing of the sound is now respecting the delay.
Arcs for the pieces sound interesting. My idea is to keep the default design as true to the original as possible, though I can add arced movement under customization. You can share your code if it roughly resembles the format of [x1;y1] -> [x2;y2] in a loop or a recursive function where the movement is devided into incremental steps. Then it is easiest to quickly implement it.
What do you mean with increased thinking time? Perhaps the node limit can be increased under Engine -> Limit - Normal / auto eval. I mainly use auto eval myself and am not too experienced with other parts of nibbler. Thanks!
Your effort is impressive! I'm trying to get access to my old DevOps repository and send you a link to the file after I have transferred everything to GitHub. I'm not sure if it meets the requirements you stated. All I remember is that these are functions that are supposed to run each frame in an Update function, in other words, dozens of times / second. :-)
Regarding thinking time. I prefer leaving the node limit at 1 or lower to make the bot play more human like. But an option to add some extra random seconds per move or increase the time spent on evaluation without increasing the strength of the engine would be cool and would make it feel more natural than an instant reaction.
Btw, in case you aren't testing on Mac, I'm using the Mac version of the Nibbler GUI (MacOS Ventura 13.2.1) and it runs perfectly with your Redesign!
Alright now I get what you mean with "x->y", since it is 2D. I think I converted it from 3D to 2D a few years back. I'll keep you posted!
I guess I only have the 3D variant, but it shouldn't be too difficult to rewrite:
Vector3 nextPos;
void TravelArc(Vector3 targetPoint)
{
float dist = (targetPoint - _startPos).magnitude;
Vector3 nextZ = Vector3.MoveTowards(transform.position, targetPoint, _speed * Time.deltaTime);
float baseY = Mathf.Lerp(_startPos.y, targetPoint.y, (nextZ - _startPos).magnitude / dist);
float arc = (_arcHeight) * ((nextZ.z - _startPos.z) * (nextZ.z - _targetPosition.z) + (nextZ.x - _startPos.x) * (nextZ.x - _targetPosition.x)) / (-0.2f * dist * dist);
nextPos = new Vector3(nextZ.x, baseY + arc, nextZ.z);
transform.LookAt(nextPos - transform.position);
transform.position = nextPos;
}
In case you want to have a look at the usage in code, here is a link to the file.
I will have to look up some functionality like Mathf.Lerp but looks otherwise doable. I will give it a try when I have some time. I am happy it works on Mac, too, thanks!
Great! I hope you'll have a nice weekend!
PS: I've tried to detach the code from the Unity API and convert it to 2D, but I have no way to test it.
// For simplification; could also be a class.
struct Vector2
{
float x = 0;
float y = 0;
public Vector2(float newX, float newY)
{
x = newX;
y = newY;
}
}
// Set by you
Piece piece;
Vector2 _initialPiecePos;
Vector2 _targetSquarePos;
// For the function
Vector2 _nextPos;
float _speed = 5;
float _arcHeight = 1;
// I used this method to replace the default movement, but I assume it could work on-top.
void TravelArc(Vector2 targetPoint)
{
Vector2 currentPiecePos = new Vector2(piece.x, piece.y);
// Distance travelled since move start.
float dist = squareroot[(targetPoint.x − _initialPiecePos.x)*2 + (targetPoint.y − _initialPiecePos.y)*2]
// Forward position next frame.
Vector2 next = (targetPoint - currentPiecePos) * _speed;
// Move along the up-axis step by step.
float fraction = squareroot[(next.x − _initialPiecePos.x)*2 + (targetPoint.y − _initialPiecePos.y)*2]
float baseY = (_initialPiecePos.y + fraction * (targetPoint.y - (_initialPiecePos.y))) / dist;
float arc = (_arcHeight) * ((next.y - _initialPiecePos.y) * (next.y - _targetSquarePos.y) + (next.x - _initialPiecePos.x) * (next.x - _targetSquarePos.x)) / (dist * dist);
piece.x = next.x;
piece.y = baseY + arc;
}
void UpdateEveryFrame()
{
TravelArc(_targetSquarePos);
}
I tried to quickly implement it. Not sure if it is what you were going for. You can also play around with some values inside "nove_eval/move_animation.js".
Here is the code:
function inc_animation2(x1, y1, x2, y2, i, bg, currentX, currentY) {
if(animation_finished) {
return;
}
let total_xdiff = x2 - x1;
let total_ydiff = y2 - y1;
let total_dist = Math.sqrt(total_xdiff * total_xdiff + total_ydiff * total_ydiff);
let pieceVecX = (x2 - currentX);
let pieceVecY = (y2 - currentY);
//pieceVecX = pieceVecX / pieceVecLength * step_length;
//pieceVecY = pieceVecY / pieceVecLength * step_length;
pieceVecX = total_xdiff / animation_steps2;
pieceVecY = total_ydiff / animation_steps2;
let nextX = x1 + pieceVecX * i;
let nextY = y1 + pieceVecY * i;
let nextDistFromStartX = nextX - x1;
let nextDistFromStartY = nextY - y1;
let nextDistFromStart = Math.sqrt(nextDistFromStartX * nextDistFromStartX + nextDistFromStartY * nextDistFromStartY);
let fraction = nextDistFromStart / total_dist;
let baseY = total_ydiff * fraction + y1;
let arcHeight = config.square_size * 5;
let arc = - easySign(total_ydiff) * arcHeight * ((nextY - y1) * (nextY - y2) + (nextX - x1) * (nextX - x2)) / (total_dist * total_dist);
moving_piece.style.top = `${baseY + arc}px`;
moving_piece.style.left = `${nextX}px`;
currentX = nextX;
currentY = nextY;
let i2 = i + 1;
if(i >= animation_steps2) {
moving_piece.style["background-image"] = null;
animation_finished = true;
hub.draw();
return;
}
setTimeout(inc_animation2, animation_step_time2, x1, y1, x2, y2, i2, bg, currentX, currentY);
}
I'm not sure why it even works the way I'm saving currentY = nextY instead of currentY = baseY + arc, but everything else didn't produce an arc. There is lots of things that can be optimized which I will do at another time.
Wow, I can't believe you already implemented this. 👍 👍 👍
I have to admit, this is already too complicated for me (long time no code). Since fully implementing this is ought to be a long term goal, I will see if I can get some information about parabola movement in the Unity forums in the meantime. These are full of "how to make grenade fly/ball bounce" questions, mostly answered by experienced coders.
Here are my 2 suggestions for improvement, for when you tackle it in the future:
PS: I know we are now in an Enhancement thread but I noticed, that in a game vs engine, the moment I drop a piece on a target square, the good move/bad move calculation makes the program freeze for a split second. Of course this could be because I'm on M1 Silicon which is, in my experience, not the best processor type for heavy chess calculations. Is it lagging on Windows PC too?
I haven't noticed any lag on an i7-11800h. It is possible that the calculation takes a bit too much time since it is not optimized at all. Rather I created most things with the objective of making it simply work first. After I implement most functionality, I will look at optimization and quality of code.
In this case, since it is clearly causing some trouble, I am going to look into it.
Considering the movement, any improvements I am happy to receive. If not it is also okay. Once I have some more time for smaller things, I can look at it myself.
Thanks again!
I ran some tests. The draw function of the icon takes on average 0.15 ms to run, which is plenty fast. The function that updates stats and visual information after every move is between 2 ms and 7 ms. This is mainly because I'm calling a pricey function that completly recalculates the move history on the right. However, I can't see this actually causing any issues.
I added some time tracking, where if you enable the dev console, you may track the time it takes for you to run the function after every move.
If you disable the evaluation completly under Display -> Show Icon Evaluation, then does it still lag?
If you use the default movement animation, is there a difference? I can see the new animation probably not being smooth.
Once I know which function causes the lag it should be easy to fix. I guess my processor is too fast for me to notice. Thanks!
I attached a console log. I'm not sure this is what you meant, because of the "Violation" tag.
The lag increases with every move on both movement types and with Evaluation Display turned off, but only when using drag and drop in a game vs an engine. The 40ms lines are the dragging and the increasing ms lines are when I drop a piece. It's a small visible delay on the board when letting go of the dragged piece but it becomes annoying during endgame. I'm at 405 ms right now after about 40-50 moves.
Tomorrow I will go through the Backend list and see if there is an option that works better with Apple Silicon cpu.
PS: The delay could also be caused by the instant movement and thus calculation of the engine. (No, not an advertisement for the "Simulated thinking time" feature, haha)
I removed a call to render the chart whenever a piece is dropped, and it is now rendered in the next frame. Since the chart is getting more complex the more moves you made, it seems like the right candidate. The function call took at most 30 ms on my pc and only if I use all 16 available threads. Once I only use 14 threads, my laptop is showing no visible delay.
Now that the function is removed, I hope your lag is also fixed. If not we may need to investigate further, for example with the performance tab on dev tools.
Let me know if this worked, thanks!
Ah great! Before testing further, is it ok to just drop the new files into the "app" folder or should I use a new Nibbler app for each update?
Just dropping it in is fine. Windows normally asks if it should replace the same files, where I press 'replace all'. Mac probably has a similiar prompt.
And btw. Next I'm going to work on an official design that is default with no cc problems. I thought maybe I will use lichess graphics that are similar. And for audio mabye you could create sounds that are very similar to the chess.com sound, but created by yourself instead, which would be great. Thanks!
Sweet, the lag is completely gone! Yeah, I'd love to create these sounds! I'm also working on a rather unusual piece set at the moment, inspired by the knight in the top left on the Hiarcs.net website.
I'll keep you posted on my progress with the sounds. I'll probably have it done in a week. If you have any preferred specifications for the audio files (size, format, naming, etc.) let me know.
I am happy to hear the lag is gone. As long as it is somewhat similar to chess.com's sound, it should be fine, including move, capture, check, promote, mate, castle. I'm not sure if I will add illegal move sound.
I also added some themes now and updated the readme. Since the core is now standing I will probably be a little bit slower with the next updates, but whenever I have time I will do the rest. And then of course additional stuff.
Feel free to comment on the default design. I tried to keep it similar to chess.com but using public resources from lichess that you linked me.
Otherwise, I am looking forward to the sound files and interested in how the default design will then feel like, thank you!
This weekend I have definitely lots of time at hand and might get the sound set done if all goes well. Since my creation approach includes Granular Synthesis to create a sample with a myriad of delicious board sounds to pick from, there might be something that fits illegal move indication well.
Btw., I love the roadmap!
Short question: Do we use Stereo or Mono sounds? The latter is more common, but if you intend to add an extravagant Stereo board sound option, I would create Stereo and Mono variant of each sample, unless you know a way to change Stereo to Mono in code.
I think for now keeping to mono should be fine.
Ok, I think I'm done. Since these sounds are exclusive for your Redesign, do you want me to send the files to an email of yours or do we keep it public? I have no bloody clue about licensing.
If you dont mind, you could make it public and just add the zip to your comment. Right now the project only has a few hundred views anyway and once everything is solid I will simply make it operate under gnu public license.
If not, I think you could keep a version of the sounds with higher sample rate/bits and make only a slightly lower resolution public on github where you make it so it requires consent. But dont trust me. I will do some research at some point, but could take a few weeks...
You helping me in this small project is already really great and I thank you very much
Don't mention it. Your project is really promising! I hope more people will come to contribute something.
Regarding the files, I simply added the folder to my Google Drive. The link is in the third post. Note that this is not a set, but candidates for you to pick from. Some similar sounds, and a few alternatives. Let me know if you would like me to add a category or change something.
Hi! Thanks again, I have finally added the sound effects! Since there are so many to choose from, I will probably add another Audio folder with more goofy sounding effects. Thank you for your effort and help :)
It's a pleasure! I just played a game with the updated version and I really like the sounds you chose. And if you think something sounds not quite right, let me know and I'll try to improve it. Also, let me know if you need help with anything else.
Sliding pieces and board sounds would make this Redesign perfect! Beautiful work!