RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

(Nujel'm) Battle Chess

Arya

Wanderer
(Nujel'm) Battle Chess

Summary:
Play chess with NPCs as pieces on the Nujel'm chessboard (or set up your own somewhere else). This script comes with a full chess logic behind it, preventing players from making illegal moves, and manages automatically game ending.

Description:
I had this script in an almost finished state for ages, and I decided to finally give it a final touch. I believe there are other battle chess scripts out there, but I don't recall any of them implementing the chess logic. This script supports the following chess features:

- Knows the moves, and it prevents pieces to make any illegal moves (providing a little feedback to the user as well).
- Analyzes the board, preventing moves that would put the mover's king under check.
- Supports castle and en passant moves
- Supports pawn promotion
- Recognizes check, checkmate and stalemate situations

The script currently does not implemet:

- The 50 moves rule
- The 3 identical moves rule

Also this script doesn't implement single player chess. If you want a computer opponent get yourself a real chess game ;)

If the game ends with a winner (as opposed to stalemate, resigning, disconnection or whatever), the winner will receive a little document which records the game stats and certifies the victory. You can disable this feature in ChessConfig.cs.

The game is piloted through a series of gumps displaying the current game status, the pieces captured by each side and the current score.

There are a number of time outs you can configure in ChessConfig.cs. By default a player can take up to 10 minutes to make a move, then they get a warning and have further 3 minutes to move. If they don't the game ends. A similar behaviour occurs when a player is disconnected, they have 10 minutes to get back in game before reset.

Staff can immediately terminate a chess game by deleting one of the NPCs on the board.

Important: the game will NOT serialize itself. The board, and the stone will, but not the game itself. Therefore if the server is rebooted, any game in progress will be lost.

As always, please report any issues.

Installation:
Unzip to your scripts folder and restart the server. Use:

[Add ChessControl

to add the game control stone.

Once the stone is placed it must be configured.

If you already have a board made (for example in Nujel'm):

Go to the stone props and set the following:
- BoardNorthWestCorner : this a Point2D value and you can set it by clicking the target location which corresponds to the board's north west cornder.
- BoardHeight : this is the location at which the NPCs will be created.
- SquareWidth (default 2): this is the width of each chessboard square.

If you don't have a chessboard ready:

If you wish the stone to create a chessboard for you, double click an unconfigured stone and target the ground. The stone will create the board and automatically configure the stone with the correct parameters.

Note: by default the script creates and uses a board where each square is 2x2 tiles. This however can be changed, from 1x1 upwards.

Updates

1.0.1, June 23: Quick fix to prevent players from playing against themselves (which could ultimately result in a server crash).
1.0.2, June 24: Fixed the problem that caused some pieces to be unable to capture when played on Felucca.
1.0.3, June 25: Fixed the crash that would occur when a pawn promotion resulted in a checkmate. Possibly fixed another crash occurring at game start when the guest would accept the game and the owner would cancel at the same time. Also the name of the parner is displayed correctly (without the serial) on the start game gump.
1.1, June 25:
- Increased NPCs speed
- NPCs reset their correct facing direction after moving
- Knights follow an L path when moving
- Changed default hues for black and white
- Added sounds to the NPCs. Each piece has a different sound for moving, attacking and being captured.
- Added a number of cosmetic properties to the stone. All those properties can be changed at any time and will serialize with the stone:
- WhiteHue and BlackHue, no explanation needed.
- AttackEffect : this is the ID of the effect performed by a NPC when attacking (before moving) another piece.
- CaptureEffect : this is the effect the NPC performs when it captures another NPC
- BoltOnDeath : specifies if a NPC's capture will be accompanied by a lightning strike
- ChessSet: choose from 5 (I think) chess sets. Currently supplied are: Classic, Fantasy, Fantasy Giant, Animal and Undead. Each set produces different NPCs and uses different sounds.
1.2, June 27:
- Added a region to the chessboard for the duration of the game. This ensures that players aren't allowed to cast invisibility on the chess pieces.
- When starting a game, the player will be able to decide whether to allow players on the chessboard or not (not allowed by default). This will avoid board cluttering. (Thanks to XLordX for these very valid suggestions)
- Added a minor hue to both black and white pieces. This will make the pieces look much better rather than using the opponent's hue. (Thanks to jjarmis for this!)
- Added a safe word to be used when for some reason you loose the target and the game gump. By default say 'game' and if the game isn't stopped you'll receive the game gump.
- Added the option to have a different orientation for the board (NS by default, EW through props). The automatic chessboard generation takes into consideration this parameter. Thanks to XxSp1derxX for this one.
- Something else I can't remember right now ;) Possibly a potential crash fix.
1.2.1, June 28:
- AllowSpectators property will now serialize correctly
- AllowSpectators and Orientation properties will now be applied real time if a game is in progress
- If the board must be rebuilt during a game, the action will be delayed until the current move is over
- OverrideMinorHue property: if set to true ignores the minor hue and uses just one hue to color the pieces.
- Double clicking the stone during a game will now reset the gumps/targets if they have been lost.
1.2.2, June 29:
- OverrideMinorHue will now also override hair and skin hue
- Fixed a potential crash when a player logs our after the game ends but before both players close their gumps.
- Staff above Counselor will always have access to the chessboard.
1.2.3 July 1:
- Fixed a crash occurring when double clicking the stone during game setup.
1.2.4 July 4:
- Hopefully finally fixed the crashing issue with players disconnecting.
- Fixed a few appearance issues on the classic chess set (Sp1der will be happy ;))
1.2.5 Sept. 28:
- Refactored the Chessboard class to BChessboard. This will prevent the crash occuring when using the [Decorate command.
- NPCs will be now ejected from the chessboard
- Fixed crash occuring when staff would delete a pawn in the middle of its promotion
- If the winner has no backpack they will not receive their winning certificate
- You can no longer check mate your enemy and win the game, while being checked yourself.
- Player can choose the preferred chess set when starting a game.
 

Attachments

  • BattleChess.1.2.5.zip
    41.3 KB · Views: 1,736

jaynigs

Wanderer
Also this script doesn't implement single player chess. If you want a computer opponent get yourself a real chess game

cool, wonder how hard it would be to put in an Ai to play the computer? if you know java i have a chess engine on my phone and it is very advanced and relatively small, maybe it can be converted to c#? just a thought...

:D
 
D

draco

Guest
Like allways Arya, a greeat job!
Im on my holiday now, on the beach outside the house. so im trying it when i get home.


Oh an idea, your the script master, a Mail Box would be cool.
 

Arya

Wanderer
jaynigs said:
cool, wonder how hard it would be to put in an Ai to play the computer? if you know java i have a chess engine on my phone and it is very advanced and relatively small, maybe it can be converted to c#? just a thought...

:D

It wouldn't be *that* hard. If you dig inside the script's code, you'll find methods that can perform simulations on the board (which is what's done to verify if there's a checkmate or stalemate). Each piece on the board has a value, and you could have functions making choices from different move plots.

However I honestly think that if you want to play chess against a computer, you should get a real program rather than do it in UO. Then you can fine tweak difficulty, get better help and so on. Not to mention that UO is supposed to be a socializing game. Anyway if anyone wants to alter the script to add an automatic players, by all means do so :)
 
this is absolutely a work of genius hehe, I defenitely need to find my win2k cd for my second pc that died the other day. Oh well... another hour or so down the bin to fix it :p
 

Llyrwech

Sorceror
First of all, I absolutely love this script. You never cease to amaze me, Arya.

However, I've found one issue. Rooks seem to not have a capture routine and thus get stuck whenever you send them to a spot on which another piece is standing. They wander about and cannot finish the move, even if you relocate the Waypoint. End result: the game has to be terminated.

I'm going to add in my own capture routine to fix this. This could lead to some pretty grumpy chess players. ^_~

Thanks once again for another excellent script.

Safe journeys,
Llyrwech

P.S. On slightly closer inspection, Rooks are the only pieces without the invulnerable orange health bar. Connection? I'm not certain. I'll continue digging.
 

Llyrwech

Sorceror
Captain The First said:
Oh I do believe the height for the chessboard in nu'jhelm is 5. At least it worked for me that way.

Two easy ways to be sure in any situation:
1) 'Props' one of the tiles and check its location value.
2) Stand on the board and use the [where command.

Safe journeys,
Llyrwech
 

Arya

Wanderer
Llyrwech, I just tried in case some late change broke something, but rooks on my system seem to behave correctly. Also they do have the yellow invul-bar (even though for some weird reason their HP are the 0 - it shouldn't be an issue though since they're all the same type of mobile with just different bodies/clothes).

Does this happen to you all the time? Or can you give me steps to reproduce the bug?
 

Llyrwech

Sorceror
It has happened to me on mutiple attempts, but so far I've only tried pawns. I'll try taking other pieces, though I doubt the routine is selective. I may also have a theory as to the reason... it may be a matter of location. I'll look into that as well. (my board is not in Nujel'm)

Safe journeys,
Llyrwech
 

Arya

Wanderer
I do all my testing on a board in green acres, so location shouldn't be an issue really. All calculations are performed on an 8x8 matrix, not in world coordinates. Also I pretty much cleared the whole board using only rooks and didn't have a single issue so far...
 

Llyrwech

Sorceror
My rooks cannot take any pieces and no, location did not matter. (I thought that, perhaps, my region rules where I was had been preventing rooks from carrying out their tasks. Not sure why what would be the case, but it was an idea at least.)

Any ideas on your end? This is the only issue of the sort I've seen, and I'm not sure what would make rooks the exception.

Safe journeys,
Llyrwech
 

Llyrwech

Sorceror
Actually, I begin to see the issue....

Felucca ruleset.

The rooks have no stamina either, so they can't push through to reach the waypoint. This also explains why they move so much slower than other pieces. Now, to simply fix their health issues. ^_~

Safe journeys,
Llyrwech
 

Arya

Wanderer
Well this is very weird, I tried and tried but my rooks perform as expected. Anyone else having this issue?

When you move a piece, a way point is created at its target location. Do you see it when you move the rook, and does it disappear when the rook reaches its location? Or it doesn't reach it at all? And if so, does it start moving? Do you still have the Make your move button in your gump?
 

Arya

Wanderer
Llyrwech said:
Actually, I begin to see the issue....

Felucca ruleset.

The rooks have no stamina either, so they can't push through to reach the waypoint. This also explains why they move so much slower than other pieces. Now, to simply fix their health issues. ^_~

Safe journeys,
Llyrwech

Uhm can you try to do an add an InitStats( 25, 100, 100 ); (or whatever you like) to ChessMobile.cs around line 25 and see if that fixes it?
 

Llyrwech

Sorceror
I had already been in the process of doing the same general thing, except I added the following starting at line 37:

Code:
			m_Piece.Str = 25;
			m_Piece.Int = 100;
			m_Piece.Dex = 100;
			m_Piece.Stam = 100;

The last bit was just my paranoia.

However, it works, now. Also, my rook is slowly regaining his health, finally, as well. Something must be quirky in his general initialization.

At any rate, thank you very much. It works wonderfully. Now, if only I could figure out how to edit Felucca rules to remove that blasted push-through issue.

Safe journeys,
Llyrwech
 

Arya

Wanderer
You were correct, it's the Felucca ruleset not allowing the rook to move through as I didn't initialize any stats. I have corrected this in the original script (didn't bother to version upgrade). You can do it yourself following what I said in my previous post.

Many thanks for helping me figure this out!
 

danknight21

Wanderer
well yes i had noticed the problem with sum of the peices not moving right...however....found a new shard crashing problem

If a player click to add a staff member 2 the game and then right as they click accept and the player clicks cancel...the shard crashed
 

yevusi

Wanderer
as most of your work Arya, it just looks fine.
keep up the good work

hmm... i might take that idea for more games like stratego :)

if only i had the time :(
 
Top