public void click(int column, int row) { uncolorButtons(); clicked = 0B000000000000000000000000000000000000000000000000000000000000001; clicked = clicked << (((row * 8) + (column))); //colorButtons(BitHelper.File[(BitHelper.setBit(clicked) % 8)], Color.Blue); //colorButtons(BitHelper.Rank[(BitHelper.setBit(clicked) / 8)], Color.Blue); Console.WriteLine("clicked column " + column + ", row " + row); if (main_game != null && main_game.type != "aiai") //interaction with the board should be prevented when two Ais are battling { if (!(main_game.type == "ai" && ki.Color == main_game.currentMove.turn)) ////interaction with the board should be prevented when the ai is thinking { Console.WriteLine("player is allowed to click"); //Console.WriteLine("Bitboard: "+Convert.ToString((long)clicked, 2)); //Console.WriteLine("All Pieces of turn " + Convert.ToString((long)main_game.currentMove.BoardAfter.AllBitboards[main_game.currentMove.turn]["All"], 2)); if ((clicked & main_game.currentMove.BoardAfter.AllBitboards[main_game.currentMove.turn]["All"]) != 0)//eigene Figur angecklickt { Console.WriteLine("player clicked one of his figures"); FromPosition = clicked; UInt64 PlaceHeCanGo = Calculator.AllPossibleForPiece(main_game.currentMove, clicked, main_game.currentMove.turn); colorButtons(PlaceHeCanGo, Color.Green); } else { Console.WriteLine("Form triggers make_move"); ToPosition = clicked; main_game.make_move(FromPosition, ToPosition); aftermove(); if (ki != null) { Console.WriteLine("KI exists"); if (ki.Color == main_game.currentMove.turn && main_game.winner == null) { Console.WriteLine("AI gets called from Form1"); myThread = new Thread(new ThreadStart(ki.call)); myThread.Start(); } } } } } }
public Move MakeAMove(UInt64 from, UInt64 to, Boolean CheckIfLegal) { bool moveSucceeded = false; if (CheckIfLegal) { if (((this.BoardAfter.AllBitboards[this.turn]["All"] & from) != 0) & (Calculator.AllPossibleForPiece(this, from, this.turn) & to) != 0) { moveSucceeded = true; } } else//wenn nicht überprüft werden soll ob der move legal ist { //einfach bewegen moveSucceeded = true; } if (moveSucceeded) { if ((from & this.BoardBefore.AllBitboards[turn]["King"]) > 0) { if (turn) { if ((to << 2 == from)) { this.BoardAfter.repositionPiece(0B0000000000000000000000000000000000000000000000000000000000000001, 0B0000000000000000000000000000000000000000000000000000000000001000); } else if (to >> 2 == from) { this.BoardAfter.repositionPiece(0B0000000000000000000000000000000000000000000000000000000010000001, 0B0000000000000000000000000000000000000000000000000000000000100000); } } else { if ((to << 2 == from)) { this.BoardAfter.repositionPiece(0B0000000100000000000000000000000000000000000000000000000000000000, 0B0000010000000000000000000000000000000000000000000000000000000000); } else if (to >> 2 == from) { this.BoardAfter.repositionPiece(0B1000000000000000000000000000000000000000000000000000000000000000, 0B00010000000000000000000000000000000000000000000000000000000000000); } } } this.BoardAfter.repositionPiece(from, to); this.from = from; this.to = to; if (this.promotion) { Console.WriteLine("promoter!"); return(this); } else { nextMove = new Move(this); nextMove.WKingSideCastleAvailable = this.WKingSideCastleAvailable; nextMove.WQueenSideCastleAvailable = this.WQueenSideCastleAvailable; nextMove.BKingSideCastleAvailable = this.BKingSideCastleAvailable; nextMove.BQueenSideCastleAvailable = this.BQueenSideCastleAvailable; return(nextMove); } } else { init(this.previousMove); //wenn move nicht gültig war Console.WriteLine("unallowed move stopped"); Console.Read(); return(this); } }