ProDeo
Would you like to react to this message? Create an account in a few clicks or log in to continue.
ProDeo

Computer Chess
 
HomeHome  CalendarCalendar  Latest imagesLatest images  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  

Post new topic   Reply to topic
 

 MAUI horror

Go down 
2 posters
Go to page : Previous  1, 2
AuthorMessage
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyTue Nov 14, 2023 5:20 pm

User-interface
Controls
Views
Display Collections
ListView


Looks like they want to kill me with their nesting depths.

Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyTue Nov 14, 2023 8:32 pm

It can be better for a beginner to work from ready-made templates to start with. There's usually a lot to learn on a new platform.
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyWed Nov 15, 2023 11:54 am

Searching for dummies:

- Add MAUI to your search string when using google for there are more ListView definitions

By the way this datatemplate worked. Difference with CollectionView is that it uses cells. So you have to add Cell. Below ViewCell is used.

Code:

 <ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="personTemplate_2">
                <ViewCell>
                    <HorizontalStackLayout>
                        <Label Margin="2"
                               Text="{Binding Name}"
                               FontAttributes="Bold" />

                        <Label Margin="2"
                               Text="{Binding Age}"
                         />
                    </HorizontalStackLayout>
                </ViewCell>
            </DataTemplate>
        </ResourceDictionary>
 </ContentPage.Resources>

  <StackLayout>
        <ListView ItemTemplate="{StaticResource personTemplate_2}" >
            
            <ListView.ItemsSource>
                <x:Array Type="{x:Type local:Person}">
                    <local:Person Name="Steve" Age="21" Location="USA" />
                    <local:Person Name="John" Age="37" Location="USA" />
                    <local:Person Name="Tom" Age="42" Location="UK" />
                    <local:Person Name="Lucas" Age="29" Location="Germany" />
                    <local:Person Name="Tariq" Age="39" Location="UK" />
                    <local:Person Name="Jane" Age="30" Location="USA" />
                </x:Array>
            </ListView.ItemsSource>
        </ListView>
    </StackLayout>





Last edited by Henk on Wed Nov 15, 2023 12:02 pm; edited 1 time in total
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyWed Nov 15, 2023 12:00 pm

For instance this template was used in a CollectionView which worked. No cell needed. (don't talk about Entry. For it makes no sense).

Code:

 <DataTemplate x:Key="personTemplate">
                <HorizontalStackLayout>
                    <Entry Text="{Binding Name}" FontAttributes="Bold" Margin="20" />
                    <Entry Text="{Binding Age}" Margin="20" />
                </HorizontalStackLayout>
  </DataTemplate>
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyTue Nov 21, 2023 3:33 pm

After ten years of debugging I found that I need to set FontFamily="Courier New" to show integer values vertically aligned correctly in labels

Talking about wasting time.

Code:

 <Label Text="{Binding Value, StringFormat= '{0, 8}' }" FontFamily="Courier New" />
Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyTue Nov 21, 2023 5:45 pm

Bring back 1970s BASIC!

Bring back mainframe terminal programming!

Something you could try: no promises, but sometimes pasting your code into ChatGPT or Bard and asking what's wrong with it actually helps you move forward.
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyFri Nov 24, 2023 2:31 pm

Strange I can play an automatic game and showing chessboard only . But when displaying variations it stops after a while. Only starting again when I click on the windows. This also happens when I don't show the chessboard.

ChapGPT:
Make sure that any UI updates, including changes to the variations displayed, are being performed on the main UI thread. Use Device.InvokeOnMainThreadAsync to marshal code execution back to the UI thread.

Consider whether resource limitations, such as high CPU or memory usage, could be affecting the application's ability to update the UI smoothly.

Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyFri Nov 24, 2023 2:34 pm

I think I have to simplify. Maybe start generating nonsense variations that show quickly. If that works I make it more clever.

O wait make a random mover. If that even does not work then it is not cpu limitation or whatever.

Maybe ui gets less and less priority from windows. But why does it not have problems when showing chessboard only.

That is without variations.
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyFri Nov 24, 2023 2:48 pm

chatGPT:

If the data binding for variations is not optimized or if updates to the variations involve frequent changes to the UI, it can lead to performance issues. Ensure that data binding is efficient, and updates are handled appropriately.
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyFri Nov 24, 2023 2:49 pm

Code:

  <CollectionView  ItemsSource="{Binding Path=Variations, Source={StaticResource chessBoardViewModel}}"  >
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                    <HorizontalStackLayout  >
                        <Label Text="{Binding Depth, StringFormat= '{0, 4}' }" FontFamily="Courier New"  />
                        <Label Text="{Binding Value, StringFormat= '{0, 8}' }" FontFamily="Courier New" />
                        <Label Text="{Binding ElapsedTimeCentiSec, StringFormat= ' {0, 8}' }"  FontFamily="Courier New" />
                        <Label Text="{Binding MoveString }" FontFamily="Courier New" />
                    </HorizontalStackLayout>
                </DataTemplate>
                </CollectionView.ItemTemplate>
        </CollectionView>
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyFri Nov 24, 2023 2:49 pm

see you later alligator.
Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyFri Nov 24, 2023 4:36 pm

Henk wrote:
see you later alligator.


Off to gel your kiss curls in place? Laughing
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyMon Nov 27, 2023 2:31 pm

After years of debugging and reading chat GPT suggestions:

Timer.Interval = TimeSpan.FromSeconds(0.5);

This helps a bit. Before I used 0.2.

But there are more problems. For instance now column of the board disappears when there are no pieces in the column. Probably I have to use a default image of an empty square.


Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyMon Nov 27, 2023 6:42 pm

Risizing window was also a problem. But chatGPT is doing the programming now.

Code:

public partial class MainPage : ContentPage
....

 protected override void OnSizeAllocated(double width, double height)
 {
 base.OnSizeAllocated(width, height);

 // Your resizing logic here
 ResizeChessboard(width, height);
 }

Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyMon Nov 27, 2023 9:04 pm

Using an AI to write your code has one big merit: it's only going to get better!
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyTue Nov 28, 2023 10:16 pm

All pieces were rewritten each time after a move. But again chatGPT fixed it for me. Took me a day to find out.

Code:

var square = viewModel.ChessBoard[k];
var imgBinding = new Binding
{
       Path = "ImageName",
       Source = square
};
 img.SetBinding(Image.SourceProperty, imgBinding);



public class Square2 : INotifyPropertyChanged
{
 string imageName;

 public Square2(string imageName)
 {
 this.ImageName = imageName;
 }

 public String ImageName
 {
 get
 {
 return imageName;
 }

 set
 {
 imageName = value;
 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ImageName)));
 }
 }
 public event PropertyChangedEventHandler PropertyChanged;
}

/// in view model

private void UpdateChessBoard(ObservableCollection<Square2> chessBoard, IChessBoard position)
{
 // Assuming ChessBoardGrid.ChessPositionToChessBoard method updates the existing collection
 ChessBoardGrid.ChessPositionToChessBoard(position, chessBoard);
}



When you create the chessboard  and the squares each time binding does not work. So you have to update the image names or urls when changed but not create new squares.


So now it works. No annoying flashings of the chessboard.
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyTue Nov 28, 2023 10:24 pm

Code:

internal static void CreateChessBoardView(IChessBoard position, ObservableCollection<Square2> chessBoard)
{
 int k = 0;
 for (int i = 0; i < 8; i++)
 {
       for (int j = 0; j < 8; j++)
       {
          var location = BitSet64.UBit((7 - i) * 8 + j);
 
          var imgName = "empty.png";
          if (position.Occupied(location))
          {
              var pieceSort = position.PieceType(location);
              imgName  = PieceType2String(pieceSort) + "_org.png";
 
          }
          if (imgName != chessBoard[k].ImageName)
          {
              chessBoard[k].ImageName = imgName;
          }
          k++;
        }
    }
}
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyWed Nov 29, 2023 9:41 am

TheSelfImprover wrote:
Using an AI to write your code has one big merit: it's only going to get better!

Why would AI get better. If people using AI get more stupid and AI gets input from the more stupid people it also gets more stupid.

So unsupervised learning only makes it smarter.   Or AI without humans.


As long as AI is more stupid than humans then one should use humans.
Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyWed Nov 29, 2023 9:57 am

Henk wrote:
TheSelfImprover wrote:
Using an AI to write your code has one big merit: it's only going to get better!

Why would AI get better. If people using AI get more stupid and AI gets input from the more stupid people it also gets more stupid.


We didn't see this effect in computer chess.
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyWed Nov 29, 2023 10:43 am

TheSelfImprover wrote:
Henk wrote:
TheSelfImprover wrote:
Using an AI to write your code has one big merit: it's only going to get better!

Why would AI get better. If people using AI get more stupid and AI gets input from the more stupid people it also gets more stupid.


We didn't see this effect in computer chess.

Because they are using unsupervised learning. And if not then human input providers  still beter than AI input providers.

So are the machines collecting training examples or are still humans involved.

Probably humans still designing the network architecture. But need not be. Parametrize everything and start the search for optimal parameters. But probably taking too many resources (time, energy ...). Each time network architecture changes it starts all over again.
Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyWed Nov 29, 2023 1:38 pm

In chess, it's easy to define an intelligent choice of move:

1. if you're winning, choose a move that gets to the win quickly

2. If you're drawing...

2a. Don't choose a move that puts you in a losing position

2b. Based on knowledge of the opponent*, choose a move that maximises their chance of making a mistake

3. If you're losing

3a. Choose a move that maximises the distance to the loss

3b. Based on knowledge of the opponent*, choose a move that maximises their chance of making a mistake

3c. Resign

*today's chess computers are not taking the nature of the opponent into account.


For writing code, I'd make a case for the following:

1. Works to specification

2. Very clear and easy for humans to read

3. Minimise database requests (in business applications, database lookups are the slow part)

4. (not usually important, but important in chess) in loops that have to be cycled a large number of times, minimise the work the CPU will have to do in each cycle
Back to top Go down
Henk




Posts : 1241
Join date : 2020-11-17

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyThu Nov 30, 2023 2:43 pm

One year later. Looks like this code works in a unit test but in Maui ? Have to try. When I have time to waste.
Has nothing to do with winboard so directory name is not correct. But who cares.

Code:

public class StockfishAnalyzer : IDisposable
 {
 private Process stockfishProcess;

 public StockfishAnalyzer()
 {
 var dir = @"C:\WinBoard-4.8.0\Stockfish";

 var exe = @"stockfish_15_x64_avx2.exe";

 Directory.SetCurrentDirectory(dir);
 stockfishProcess = new Process();
 stockfishProcess.StartInfo.FileName = exe;
 stockfishProcess.StartInfo.UseShellExecute = false;
 stockfishProcess.StartInfo.RedirectStandardInput = true;
 stockfishProcess.StartInfo.RedirectStandardOutput = true;
 stockfishProcess.StartInfo.CreateNoWindow = true;

 stockfishProcess.Start();
 SendCommand("uci");
 WaitForResponse();
 }

 

 public async Task<string> AnalyzePosition(string fen, int timeMilli)
 {
 SendCommand($"position fen {fen}");
 SendCommand($"go movetime {timeMilli}"); // Adjust the analysis time as needed
 await Task.Delay(timeMilli);
 return WaitForResponse();
 }

 private void SendCommand(string command)
 {
 stockfishProcess.StandardInput.WriteLine(command);
 }

 private string WaitForResponse()
 {
 StringWriter sw = new StringWriter();
 stockfishProcess.StandardInput.WriteLine("isready");
 while (true)
 {
 string output = stockfishProcess.StandardOutput.ReadLine();
 if (output == "readyok")
 {
 break;
 }
 else
 {
 sw.WriteLine(output);
 }
 }
 var result = sw.ToString();
 return result;
 }
 


 public void Dispose()
 {
 // Close the Stockfish process when done
 stockfishProcess.StandardInput.WriteLine("quit");
 stockfishProcess.WaitForExit();
 stockfishProcess.Close();
 }
 }
Back to top Go down
TheSelfImprover

TheSelfImprover


Posts : 2920
Join date : 2020-11-18

MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 EmptyThu Nov 30, 2023 6:17 pm

Might work on Windows, but wouldn't expect it to work on Android.
Back to top Go down
Sponsored content





MAUI horror - Page 2 Empty
PostSubject: Re: MAUI horror   MAUI horror - Page 2 Empty

Back to top Go down
 
MAUI horror
Back to top 
Page 2 of 2Go to page : Previous  1, 2

Permissions in this forum:You can reply to topics in this forum
ProDeo :: Programmer Corner-
Post new topic   Reply to topicJump to: