Java Chess Programming Video #17 The Player (Part I)

preview_player
Показать описание

Chess Code Repository :

IDE:

Reading Material:
Рекомендации по теме
Комментарии
Автор

I'm 5 years late, but this series has been amazing so far. Can't say I understand it all, but I hope to modify it to Chess 2 The Sequel. Thanks!

mathcatz
Автор

Hey amir, instead of making isKing() method abstract and overriding it on all of the PieceType, you could've returned false on isKing(), and just override it on the King PieceType, this would prevent copy-pasting the same block of code at 5 places, and you could also prevent violating DRY principle. If I'm wrong, please correct me, Amir.

justforjava
Автор

Loving this series so far, subscribed as well!
I wonder if there is anything wrong with writing instead of .isKing()

ShervinKoushan
Автор

Just a little tip: When you do a cast at establishKing() you are basically doing an instanceOf operation beforehand.
I guess you've been told a million times that instanceOf is bad, and you should never use it, but if you declare a method that does exactly the same thing what instanceOf does while actually making an overhead that is unnecessary, you didn't really solve that problem.
But: the problem is not with you, but with the general idea that instanceOf is a bad thing. It's not a bad thing,
polymorphism is not always the answer to every problem, and this is one of those problems.

bencekovacs
Автор

Why create and use a dedicated field for PieceType in each Piece? I just made an abstract method in Piece class and overrode it returning the PieceType.PIECE_NAME is it ok or creating field have some additional benefit? Thanks!

ankurg_
Автор

I've made the pieces return their respective letter using toString() instead of using an enum. So, my code became :
{..}
Is this alright or do I have to use the enum in the long run?

SrikarKrishna
Автор

I keep getting "Exception in thread "main" java.lang.ClassCastException: Chess.Pieces.Knight cannot be cast to Chess.Pieces.King" but I return false for my isKing() method for everything except for the king. Am I doing something wrong??

Prophetelf
Автор

thanks a lot !!! but here what do this method stablishKing() do ??

abdh
Автор

can't find the next video ? can you pl link me upto it ?

zhiuzha
Автор

I've tried the exact same code but it's giving me exceptions

muhammadfahadarshad