15,881,967 members
1.00/5 (1 vote)
See more:
```Problem Statement
Project: Chess Metrics

The game of chess is deeply complex, but it can be interesting to study from a metrics and analysis point of view. Your task is to develop a software tool that, given the input of a sequence of moves in a chess game, outputs the count of each unique piece taken and the average number of moves it takes to capture each type of piece.

Inputs:
The program will receive a list of strings representing the sequence of moves in a standard game of chess. Each string is formatted according to the standard algebraic notation (SAN) of chess moves, without additional markings like check or checkmate symbols.

Outputs:
The program should return a dictionary, where keys are the types of pieces captured ("pawn", "rook", "knight", "bishop", "queen", and "king") and the corresponding values are tuples of two elements: the count of that type of piece captured, and the average number of moves taken to capture each instance of that type of piece.

For the purposes of this problem, we will ignore the distinction between different colours of pieces. All piece captures, whether of black pieces or white pieces, should be included in the same count.

If no piece of a certain type has been captured during the game, that piece should not appear in the output dictionary.

Example:
Input:

["e4", "e5", "Nf3", "Nc6", "Bb5", "a6", "Bxc6"]"
Output:

{"pawn": (0, 0), "rook": (0, 0), "knight": (1, 7), "bishop": (0, 0), "queen": (0, 0), "king": (0, 0)}

In this example, the seventh move "Bxc6" means a bishop captured a knight. Hence, the count for knight is 1, and it took 7 moves for it to be captured.

Constraints:
All inputs will be valid and formatted correctly according to the standard algebraic notation (SAN) of chess moves.
The list of moves will not be longer than 500 elements.
The game represented by the sequence of moves can be in any state: it can be complete, incomplete, or even impossible in a real game of chess.
Remember, the main challenge in this problem is not just to code the solution, but to understand the rules and conventions of the chess game, and translate that into a program.```

What I have tried:

I haven't really start working on it yet. I don't know how to approach this question.
Posted
Updated 16-Jul-23 18:24pm

## Solution 1

Homework = good fun. It looks like they have used what you have learned in class. Break down each part into smaller pieces, then it should be easier to code.

I'll do one part for you:
`The program should return a dictionary, where keys are the types of pieces captured ("pawn", "rook", "knight", "bishop", "queen", and "king") and the corresponding values are tuples of two elements: the count of that type of piece captured, and the average number of moves taken to capture each instance of that type of piece.`

They describe it in json notation for you:
JavaScript
```{
"pawn": (0, 0),
"rook": (0, 0),
"knight": (1, 7),
"bishop": (0, 0),
"queen": (0, 0),
"king": (0, 0)
}```

Here they want a generic dictionary (in C# as no language was tagged):
C#
```Dictionary<string, (int count, int avgMoves)> CapturedPieces
= new Dictionary<string, (int count, int avgMoves)>();```

Now, you need to apply what you have learned, break down the task into smaller tasks, and write the code.

Hill Phatpanichot 16-Jul-23 21:48pm
Thank you very much, I should be good from here.
Patrice T 17-Jul-23 3:55am
+5
Graeme_Grant 17-Jul-23 4:01am
Thanks 😊

## Solution 2

Quote:
I haven't really start working on it yet. I don't know how to approach this question.

Not a solution to your problem, but something that will help you in the run.
Program Development by Stepwise Refinement[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]

- Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
Program Development by Stepwise Refinement[^]

Those links should help you analyze problems and break them down to logical parts that are easier to handle and organize.

## Solution 3

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Richard MacCutchan 80 Pete O'Hanlon 70 Rick York 20 Gerardo Gamo 10 KarstenK 10
 Pete O'Hanlon 1,940 OriginalGriff 1,415 Graeme_Grant 895 Richard Deeming 853 Dave Kreskowiak 694

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900