본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 68

반응형

Q>

Almost everyone in the world knows about the ancient game Chess and has at least a basic understanding of its rules.

(세계의 거의 모든 사람들이 고대 게임 체스에 대해 알고 있으며 최소한 규칙을 이해하고 있습니다.)

It has various units with a wide range of movement patterns allowing for a huge number of possible different game positions (for example Number of possible chess games at the end of the n-th plies.) For this mission, we will examine the movements and behavior of chess pawns.

(그것은 가능한 많은 다른 게임 위치 (예를 들어, n 번째 플 레이어 끝에 가능한 체스 게임의 수)를 허용하는 넓은 범위의 운동 패턴을 가진 다양한 유닛을 가지고 있습니다. 이 임무를 위해, 우리는 움직임과 체스 졸의 행동.)

Chess is a two-player strategy game played on a checkered game board laid out in eight rows (called ranks and denoted with numbers 1 to 8) and eight columns (called files and denoted with letters a to h) of squares.

(체스는 8 개의 행 (랭크라고 불리는 1에서 8까지의 숫자로 표시)과 8 개의 열 (파일이라고하며 문자 a에서 h로 표시)로 구성된 체크 무늬 게임 보드에서 진행되는 2 인용 전략 게임입니다.)

Each square of the chessboard is identified by a unique coordinate pair — a letter and a number (ex, "a1", "h8", "d6").

(체스 판의 각 사각형은 문자와 숫자 (예 : "a1", "h8", "d6")와 같은 고유 한 좌표 쌍으로 식별됩니다.)

For this mission we only need to concern ourselves with pawns.

(이 임무를 위해 우리는 졸 (pawns)에 대해서만 관심을 가질 필요가 있습니다.)

A pawn may capture an opponent's piece on a square diagonally in front of it on an adjacent file, by moving to that square.

(폰 (pawn)은 상대방의 조각을 그 파일의 대각선으로 그 정사각형으로 옮길 수 있습니다.)

For white pawns the front squares are squares with greater row number than the square they currently occupy.

(흰색 졸의 경우 앞 정사각형은 현재 차지하고있는 정사각형보다 큰 행 번호의 정사각형입니다.)

A pawn is generally a weak unit, but we have 8 of them which we can use to build a pawn defense wall.

(폰은 일반적으로 약한 유닛이지만 우리는 폰 방어벽을 만드는 데 사용할 수있는 유닛이 8 개 있습니다.)

With this strategy, one pawn defends the others.

(이 전략으로 한 폰은 다른 플레이어를 방어합니다.)

A pawn is safe if another pawn can capture a unit on that square.

(다른 전당포가 그 칸에있는 유닛을 붙잡을 수 있다면 폰은 안전합니다.)

We have several white pawns on the chess board and only white pawns.

(체스 판에는 여러 개의 흰 심금이 있고 흰 심황은 있습니다.)

You should design your code to find how many pawns are safe.

(얼마나 많은 폰이 안전한 지 찾기 위해 코드를 설계해야합니다.)

You are given a set of square coordinates where we have placed white pawns.

(우리는 백색 심을 놓은 사각형 좌표 집합을받습니다.)

You should count how many pawns are safe.

(얼마나 많은 폰이 안전한지 계산해야합니다.)

 

Input: Placed pawns coordinates as a set of strings.

         (폰 배열을 문자열 집합으로 배치합니다.)

 

Output: The number of safe pawns as a integer.

           (안전한 폰의 수를 정수로 나타냅니다.)

 

Example:

safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1

 

How it is used: For a game AI one of the important tasks is the ability to estimate game state.

                     (게임 AI의 경우 중요한 작업 중 하나는 게임 상태를 추정하는 것입니다.)

                     This concept will show how you can do this on the simple chess figures positions.

                     (이 개념은 간단한 체스 피규어 포지션에서이를 수행 할 수있는 방법을 보여줍니다.)

 

Precondition: 0 < pawns ≤ 8

 

A>

def safe_pawns(pawns: set) -> int:
    pawns = sorted(list(pawns), reverse=True, key=lambda x:x[1])
    safe = 0
    for i in pawns:
        map1 = chr(ord(i[0]) - 1) + chr(ord(i[1]) - 1)
        map2 = chr(ord(i[0]) + 1) + chr(ord(i[1]) - 1)
        safe += (map1 in pawns or map2 in pawns)
    return safe

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert safe_pawns({"b4", "d4", "f4", "c3", "e3", "g5", "d2"}) == 6
    assert safe_pawns({"b4", "c4", "d4", "e4", "f4", "g4", "e5"}) == 1
    print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")

 

O>

Coding complete? Click 'Check' to review your tests and earn cool rewards!

 

S>

https://py.checkio.org/

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 70  (0) 2019.06.15
Python Learn the basics Quiz 69  (0) 2019.06.15
Python Learn the basics Quiz 67  (0) 2019.06.14
Python Learn the basics Quiz 66  (0) 2019.06.14
Python Learn the basics Quiz 65  (0) 2019.06.14