कीचड़: क्षेत्र युद्ध


18

तुम गालियों के गिला हो। स्वाभाविक रूप से, कीचड़ होने के नाते, आप जितना संभव हो उतना क्षेत्र पर ऊब करना चाहते हैं। लेकिन वहाँ 3 अन्य slimes जो सटीक एक ही काम करना चाहते हैं। श्रेष्ठ गद्यकार कौन होगा?

विवरण

सभी अखाड़ों को एक अखाड़े में इकट्ठा किया जाएगा। न्यायाधीश (यानी नियंत्रण कार्यक्रम) सभी संभावित 4-कीचड़ संयोजनों की एक विस्तृत सूची के माध्यम से जाएंगे, उन्हें एक मेज के कोनों पर रखेंगे, और यह देखने के लिए देखेंगे कि सबसे अधिक क्षेत्र में कौन से कीचड़ निकलता है।

आपके स्लैम प्रत्येक मोड़ पर 3 क्रियाओं में से एक कर सकते हैं: बाहर फैलाएं, कूदें, या मर्ज करें। आगे इनका क्या अर्थ है यह आउटपुट अनुभाग में प्रदान किया जाएगा ।

बोर्ड / अखाड़ा

अखाड़ा एक वर्ग बोर्ड होगा (वर्तमान में 8x8, लेकिन यह भविष्य में बदल सकता है)। यहाँ एक खेल का एक उदाहरण है प्रगति में:

11111222
11111444
11.22444
.1222.4.
333.3244
33333.44
333...44
333....4

कीचड़ 1 (4 से 1 खिलाड़ी) के माध्यम से संख्या 1 द्वारा दर्शाया गया है, और खाली स्थान एक डॉट ( .) द्वारा दर्शाया गया है । प्रारंभ में, बोर्ड सभी खाली स्थान के रूप में शीर्ष 1 बाएं कोने में खिलाड़ी 1 के कीचड़ की एक इकाई को छोड़कर, शीर्ष दाएं में खिलाड़ी 2, नीचे बाएं में खिलाड़ी 3 और नीचे दाईं ओर खिलाड़ी 4 को छोड़कर शुरू होता है।

कोड में पठनीयता के लिए निर्देशांक 0-आधारित पंक्ति और स्तंभ सूचकांक द्वारा दर्शाए जाते हैं। उदाहरण के लिए, निर्देशांक (3, 6) 4 वीं पंक्ति में 7 वें वर्ग का प्रतिनिधित्व करते हैं (उपरोक्त उदाहरण में, ए 4)। (इससे वर्गों का उपयोग करना आसान हो जाता है:) board[coords.x][coords.y]यहां एक दृश्य चित्रण है:

(0, 0) (0, 1) (0, 2)
(1, 0) (1, 1) (1, 2)
(2, 0) (2, 1) (2, 2)

इनपुट

आपके प्रोग्राम का इनपुट होगा कि आप कौन से खिलाड़ी हैं (1, 2, 3, या 4), एक अल्पविराम ( ,), फिर बोर्ड / अखाड़े की सामग्री (नए सिरे से अल्पविराम से प्रतिस्थापित)। उदाहरण के लिए, यदि आप उपरोक्त परिदृश्य में खिलाड़ी 3 थे, तो आपका इनपुट होगा:

3,11111222,11111444,11.22444,.1222.4.,333.3244,33333.44,333...44,333....4

उत्पादन

आपके प्रोग्राम में 4 पूर्णांकों का आउटपुट होना चाहिए। पहले दो पंक्ति और स्तंभ अनुक्रमणिका हैं, जिस क्रम में आप चलना चाहते हैं, और अगले दो पंक्ति और स्तंभ अनुक्रमणिका हैं जहाँ आप उन्हें स्थानांतरित करना चाहते हैं।

आपके पास प्रत्येक मोड़ पर तीन विकल्प हैं: बाहर फैलाएं, कूदें, या मर्ज करें।

  • फैलाना

    फैलाने के लिए, लक्ष्य निर्देशांक को ले जाया जा रहा कीचड़ से बिल्कुल एक वर्ग दूर होना चाहिए, और लक्ष्य निर्देशांक पर वर्ग खाली जगह होना चाहिए। फैलते समय, लक्ष्य निर्देशांक पर एक नया कीचड़ बनाया जाता है और पुराने कीचड़ को हटाया नहीं जाता है। नया कीचड़ बनने के बाद, इस नए कीचड़ के आसपास के 8 चौकों में सभी दुश्मन स्लैम चले गए खिलाड़ी में बदल जाते हैं।

    उदाहरण के लिए, छवि 1 में बोर्ड के साथ, यदि खिलाड़ी 1 आउटपुट के लिए था 0 1 1 2, तो परिणाम छवि 2 में बोर्ड होगा।

    1.         2.
      11.22      11.12
      1..22      1.112
      ..22.      ..11.
      .....      .....
    
  • कूद

    कूदने के लिए, लक्ष्य निर्देशांक को ले जाया जा रहा कीचड़ से बिल्कुल दो वर्ग दूर होना चाहिए, और लक्ष्य निर्देशांक पर वर्ग खाली स्थान होना चाहिए। जुपिंग करते समय, लक्ष्य निर्देशांक पर एक नया कीचड़ बनाया जाता है और पुराने कीचड़ को हटा दिया जाता है। नया कीचड़ बनने के बाद, इस नए कीचड़ के आसपास के 8 चौकों में सभी दुश्मन स्लैम चले गए खिलाड़ी में बदल जाते हैं।

    उदाहरण के लिए, छवि 1 में बोर्ड के साथ, यदि खिलाड़ी 1 आउटपुट के लिए था 0 1 2 3, तो परिणाम छवि 2 में बोर्ड होगा।

    1.         2.    
      11..2      1...2
      1...2      1...1
      ....2      ...11
      ...22      ...11
    
  • मर्ज

    मर्ज करने के लिए, लक्ष्य निर्देशांक को ले जाया जा रहा कीचड़ से बिल्कुल एक वर्ग की दूरी पर होना चाहिए, और लक्ष्य निर्देशांक पर वर्ग एक ही खिलाड़ी का कीचड़ होना चाहिए। विलय होने पर, पुराने कीचड़ को हटा दिया जाता है। फिर, लक्ष्य कीचड़ के चारों ओर 8 चौकों में सभी खाली स्थान उस खिलाड़ी में परिवर्तित हो जाते हैं जो स्थानांतरित हो गए (पुराने कीचड़ को स्थानांतरित नहीं किया जा रहा है)।

    उदाहरण के लिए, छवि 1 में बोर्ड के साथ, यदि खिलाड़ी 1 आउटपुट के लिए था 0 1 1 2, तो परिणाम छवि 2 में बोर्ड होगा।

    1.         2.
      11..2      1.112
      1.1.2      11112
      ....2      .1112
      ..222      ..222
    

आप केवल अवैध निर्देशांक (उदा। 0 0 0 0) को आउटपुट करके भी पास कर सकते हैं ।

नियम और बाधाएँ

अतिरिक्त नियम हैं:

  • डेटा को बनाए रखने के लिए आप अपने स्वयं के फ़ोल्डर में फ़ाइलों को पढ़ और लिख सकते हैं (प्रस्तुतियाँ संग्रहीत की जाएंगी players/YourBotName/yourBotName.language), लेकिन आप इसके अलावा किसी अन्य चीज को संशोधित या एक्सेस नहीं कर सकते हैं। इंटरनेट का उपयोग निषिद्ध है।
  • आपके सबमिशन को विशेष रूप से किसी अन्य सबमिशन में मदद या चोट पहुंचाने के लिए कोडित नहीं किया जा सकता है। (आपके पास कई प्रस्तुतियाँ हो सकती हैं, लेकिन उन्हें विशेष रूप से किसी भी तरह से एक-दूसरे के साथ बातचीत नहीं करनी चाहिए।)
  • आपके सबमिशन को प्रति सेकंड 0.1 सेकंड से अधिक नहीं लेना चाहिए। यदि आपकी सबमिशन में कभी-कभी 0.105 सेकंड लगते हैं, तो यह ठीक है, लेकिन इस समय सीमा की तुलना में इसमें लगातार अधिक समय नहीं लग सकता है। (यह मुख्य रूप से अधिक समय लेने वाले परीक्षण से बचने के लिए एक स्वच्छता जांच है।)
  • आपका सबमिशन दूसरे की सटीक डुप्लिकेट (यानी सटीक समान तर्क का उपयोग) नहीं होना चाहिए, भले ही वह किसी अन्य भाषा में हो।
  • आपका सबमिशन एक गंभीर सबमिशन होना चाहिए। यह राय-आधारित है, लेकिन यदि आपका प्रस्तुतिकरण स्पष्ट रूप से चुनौती को हल करने का प्रयास नहीं कर रहा है (उदाहरण के लिए यदि आप हर मोड़ से गुजरते हैं), तो यह अयोग्य होगा।

यदि आपका सबमिशन इनमें से किसी भी नियम को तोड़ता है या विनिर्देश का पालन नहीं करता है, तो इसे अयोग्य घोषित कर दिया जाएगा, हटा दिया playerlist.txtजाएगा और खेल शुरू से शुरू हो जाएगा। यदि आपका सबमिशन अयोग्य है, तो मैं आपके पोस्ट पर एक टिप्पणी छोड़ दूंगा कि क्यों। अन्यथा, आपका सबमिशन लीडरबोर्ड में जोड़ा जाएगा। (यदि आप लीडरबोर्ड पर अपना सबमिशन नहीं देखते हैं, तो आपके पोस्ट पर कोई व्याख्यात्मक टिप्पणी नहीं है, और नीचे दिए गए "अंतिम अद्यतन" से पहले अपना सबमिशन पोस्ट किया है, कृपया मुझे बताएं! मैं अनजाने में इसे अनदेखा कर सकता हूं।)

अपनी प्रविष्टि में, कृपया शामिल करें:

  • एक नाम।
  • एक शेल कमांड (उदाहरण के लिए, अपने कार्यक्रम चलाने के लिए java MyBot.java, ruby MyBot.rb, python3 MyBot.py, आदि)।
    • ध्यान दें कि इनपुट (आपका खिलाड़ी और मानचित्र) को कमांड लाइन तर्क के रूप में जोड़ा जाएगा।
    • कार्यक्रमों को Ubuntu 14.04 पर परीक्षण किया जाएगा, इसलिए सुनिश्चित करें कि आपका कोड उस पर (स्वतंत्र रूप से) चलाया जा सकता है।
  • एक संस्करण संख्या, यदि आपका कोड आपकी भाषा के विभिन्न संस्करणों पर अलग तरह से काम करता है।
  • आपका बॉट कोड।
  • यदि आवश्यक हो, तो कोड को संकलित करने के निर्देश।

नियंत्रक कोड / परीक्षण, उदाहरण बॉट

नियंत्रक कोड C ++ में लिखा गया है, और इसे जीथब पर पाया जा सकता है । अपने कोड को चलाने और परीक्षण करने के तरीके के बारे में और निर्देश वहां मिल सकते हैं।

simplebot.rb, एक बहुत ही साधारण बॉट जो प्रत्येक मोड़ पर एक यादृच्छिक स्थान पर एक यादृच्छिक कीचड़ फैलाता है या कूदता है, उसे भी गिथूब पर पोस्ट किया जाता है

स्कोरिंग और लीडरबोर्ड

जब बोर्ड पर सभी वर्ग भरे जाते हैं, तो खेल समाप्त हो जाता है और स्कोर की गणना की जाती है। एक खिलाड़ी का अंतिम स्कोर वर्गों की राशि है जो खेल के अंत में अपने कीचड़ को समाहित करता है। यदि 2000 मोड़ बीत चुके हैं (प्रत्येक खिलाड़ी के लिए 500) और खेल अभी भी खत्म नहीं हुआ है, तो खेल वैसे भी समाप्त हो जाएगा और स्कोर की रिपोर्ट की जाएगी जैसे कि खेल समाप्त हो गया था।

टूर्नामेंट के अंत में, सभी खेलों के स्कोर प्रत्येक खिलाड़ी के अंतिम स्कोर की गणना करने के लिए औसत होंगे, जिसे लीडरबोर्ड पर पोस्ट किया जाएगा। कोई जमा करने की समय सीमा नहीं है; मैं समय-समय पर लीडरबोर्ड को अपडेट करता रहूंगा क्योंकि नए सबमिशन आते हैं।

एक वास्तविक लीडरबोर्ड प्रकट होने तक 4 प्रस्तुतियाँ आवश्यक हैं।

+--------------------------+-----------+--------------------+
| Name                     | Avg Score | Last Updated (UTC) |
+--------------------------+-----------+--------------------+
| GreedySlime              | 47.000    | Jul 22 10:27 PM    |
| Jumper                   | 12.000    | Jul 22 10:27 PM    |
| ShallowBlue              | 5.000     | Jul 22 10:27 PM    |
| Lichen                   | 0.000     | Jul 22 10:27 PM    |
+--------------------------+-----------+--------------------+

अंतिम अपडेट: जुलाई 22 10:27 PM (UTC)।


हम्म, मैं इसे याद कर सकता हूं, लेकिन क्या आपने बताया कि खिलाड़ियों के बीच बातचीत कैसे होगी? क्या सभी एक ही समय पर चलते हैं? खिलाड़ी 1 पहले?
justhalf

1
शायद यह सिर्फ मुझे है कि यह थोड़ा अस्पष्ट लगता है, लेकिन आप "दो वर्गों को दूर" कैसे परिभाषित करते हैं, बिल्कुल?
अर्शजी जूल

नब्बे के दशक के एक ड्रिंक के आधार पर मुझे बहुत कुछ याद दिलाता है। ;-)
बेनी

@ अन्याय प्लेयर 1 पहले चलता है।
दरवाज़े

1
@ वर्षाजी "दो वर्ग दूर" का अर्थ है, औपचारिक रूप से, "किसी भी स्थिति में जहां एक्स में अधिकतम परिवर्तन और वाई में परिवर्तन 2 के बराबर है।"
दरवाज़े

जवाबों:


4

GreedySlime

बस चाल है कि कीचड़ इकाइयों का सबसे बड़ा शुद्ध लाभ पैदा करता है।

ध्यान दें कि यह पायथन 2.x में लिखा गया है

def gen_moves(board, pos):
    """Generate valid moves for a given position.

    Return value is a tuple of the form
       (type, from_x, from_y, to_x, to_y)

    The move 'type' is a single character with:
        - 's' = spread
        - 'j' = jump
        - 'm' = merge
    """

    N = len(board)
    x0, y0 = pos
    player = board[x0][y0]

    for i in -2,-1,0,1,2:
        for j in -2,-1,0,1,2:
            if (i == 0 and j == 0):
                continue

            x1, y1 = x0 + i, y0 + j

            if not ((0 <= x1 < N) and (0 <= y1 < N)):
                continue

            c = board[x1][y1]

            if -1 <= i <= 1 and -1 <= j <= 1:
                if c == '.':
                    yield ('s', x0, y0, x1, y1)
                elif c == player:
                    yield ('m', x0, y0, x1, y1)
            else:
                if c == '.':
                    yield ('j', x0, y0, x1, y1)

def eval_move(board, move, initial_net={'s': 1, 'j': 0, 'm': -1}):
    """Evaluates given move in given context.

    - Assumes move is valid.
    - `move` argument is a tuple of the form
       (type, from_x, from_y, to_x, to_y)
    - The move 'type' is a single character with:
        - 's' = spread
        - 'j' = jump
        - 'm' = merge
    """

    N = len(board)
    move_type = move[0]
    x0, y0, x1, y1 = move[1:]
    player = board[x0][y0]

    net = initial_net[move_type]
    for i in -1,0,1:
        for j in -1,0,1:
            if (i == 0 and j == 0):
                continue

            x2, y2 = x1 + i, y1 + j

            if not ((0 <= x2 < N) and (0 <= y2 < N)):
                continue

            c = board[x2][y2]

            if (move_type == 'm' and c == '.') or (move_type != 'm' and c != player and c != '.'):
                net += 1

    return net

def main():
    from sys import argv
    data = argv[1]

    player, board = data.split(',', 1)
    board = map(list, board.split(','))
    N = len(board)

    all_pos_gen = ((a,b) for a in range(N) for b in range(N) if board[a][b] == player)
    all_move_gen = (move for pos in all_pos_gen for move in gen_moves(board, pos))
    move = max(all_move_gen, key=lambda move: eval_move(board, move))

    print move[1], move[2], move[3], move[4]

if __name__ == "__main__":
    main()

उदाहरण रन (चुनौती विवरण में दिए गए उदाहरण का उपयोग करके, और कोड को संभालने वाली फ़ाइल में सहेजा गया है slime.py):

$ python slime.py 3,11111222,11111444,11.22444,.1222.4.,333.3244,33333.44,333...44,333....4
4 0 2 2

3

उथला नीला

उथला नीला यह पता लगाने की कोशिश करता है कि भविष्य में संभावित चालों की एक संपूर्ण वृक्ष-खोज करके क्या हो सकता है , दुर्भाग्य से, वह अपने अगले मोड़ से आगे नहीं बढ़ पाता है। फिर वह अपने अगले मोड़ के बाद प्रत्येक संभावित बोर्डस्टेट पर कुछ आधा-गधा स्कोर करता है, समान रूप से हास्यास्पद सूत्र के साथ प्रत्येक व्यक्तिगत शाखा के लिए एक स्कोर की गणना करता है: और वॉयला आदर्श चाल ज्ञात है!

संपादित करें: मूल कोड बहुत धीरे-धीरे चल रहा था इसलिए मैंने इसे संशोधित किया ताकि यह केवल सभी संभावित चालों का एक यादृच्छिक नमूना ले। यह संभव है कि जब सभी चालें चलें और जब ज्यादा चाल चलें तो एक छोटा प्रतिशत संभव हो।

import java.awt.Point;  

    public class ShallowBlue {
        private static final int MAX_ROUNDS = 5, PLAYERS = 4;
        static int me = 0;

        public static void main(String[] args) {
            if (args[0] == null) {
                return;
            }

            me = Integer.parseInt(args[0].split(",", 2)[0]);
    String board = args[0].split(",", 2)[1];

    System.out.println(getBestMove(board, me, MAX_ROUNDS - 1));
}

private static String getBestMove(String board, int player, int rounds) {
    String [] boards = new String[24];
    int checkedBoards = 1;
    char playerChar = Integer.toString(player).charAt(0);
    String tempMove = getMove(0, 0, 0, 0);
    String tempBoard = calculateMove(board, tempMove); 
    boards[0] = tempBoard;
    String bestMove = tempMove;
    double us = numberOfUs(board, playerChar); 
    double skip = (us*2.5/(us*2.5 + 1))/4 + 0.735;
    if (rounds == MAX_ROUNDS - 2) {
        skip = skip*skip;
    }

    float bestScore, worstScore, averageScore, tempScore;
    int scores;

    if (rounds == 0) {
        tempScore = calculateScore(tempBoard, MAX_ROUNDS - rounds - 1);
    } else {
        tempScore = getScore(getBestMove(tempBoard, player%PLAYERS + 1, rounds - 1));
    }

    scores = 1;
    bestScore = tempScore;
    worstScore = tempScore;
    averageScore = tempScore;

    for (int x = 0; x < 8; x++) {
        for (int y = 0; y < 8; y++) {
            if (getCharAt(board, x, y) == playerChar) {
                Point[] possibleMergers = getNeighboringMatches(board, new Point(x, y), playerChar);
                if (possibleMergers[0] != null) {
                    tempMove = getMove(possibleMergers[0].x, possibleMergers[0].y, x, y); 
                    tempBoard = calculateMove(board, tempMove);
                    if (addIfUnique(boards, tempBoard, checkedBoards)) {
                        checkedBoards++;
                        if ((rounds != MAX_ROUNDS - 1) && (rounds == 0 || Math.random() < skip)) {
                            tempScore = calculateScore(tempBoard, MAX_ROUNDS - rounds - 1);
                        } else {
                            tempScore = getScore(getBestMove(tempBoard, player%PLAYERS + 1, rounds - 1));
                        }

                        if (tempScore > bestScore) {
                            bestMove = tempMove;
                        }
                        bestScore = Math.max(tempScore, bestScore);
                        worstScore = Math.min(tempScore, worstScore);

                        scores++;
                        averageScore = (averageScore*(scores - 1) + tempScore)/scores;
                    }
                }
            } else if (getCharAt(board, x, y) == '.') {
                Point[] possibleSpreaders = getNeighboringMatches(board, new Point(x, y), playerChar);
                int i = 0;
                while (i < possibleSpreaders.length && possibleSpreaders[i] != null) {
                    tempMove = getMove(possibleSpreaders[i].x, possibleSpreaders[i].y, x, y); 
                    tempBoard = calculateMove(board, tempMove);
                    if ((rounds != MAX_ROUNDS - 1) && (rounds == 0 || Math.random() < skip)) {
                        tempScore = calculateScore(tempBoard, MAX_ROUNDS - rounds - 1);
                    } else {
                        tempScore = getScore(getBestMove(tempBoard, player%PLAYERS + 1, rounds - 1));
                    }

                    if (tempScore > bestScore) {
                        bestMove = tempMove;
                    }
                    bestScore = Math.max(tempScore, bestScore);
                    worstScore = Math.min(tempScore, worstScore);

                    scores++;
                    averageScore = (averageScore*(scores - 1) + tempScore)/scores;

                    i++;
                }
                Point[] possibleJumpers = getNextNeighboringMatches(board, new Point(x, y), playerChar);
                i = 0;
                while (i < possibleJumpers.length && possibleJumpers[i] != null) {
                    tempMove = getMove(possibleJumpers[i].x, possibleJumpers[i].y, x, y); 
                    tempBoard = calculateMove(board, tempMove);
                    if ((rounds != MAX_ROUNDS - 1) && (rounds == 0 || Math.random() < skip)) {
                        tempScore = calculateScore(tempBoard, MAX_ROUNDS - rounds - 1);
                    } else {
                        tempScore = getScore(getBestMove(tempBoard, player%PLAYERS + 1, rounds - 1));
                    }

                    if (tempScore > bestScore) {
                        bestMove = tempMove;
                    }
                    bestScore = Math.max(tempScore, bestScore);
                    worstScore = Math.min(tempScore, worstScore);

                    scores++;
                    averageScore = (averageScore*(scores - 1) + tempScore)/scores;

                    i++;
                }
            }
        }
    }

    if (rounds == MAX_ROUNDS - 1) {
        return (bestMove);
    } else {
        return getScoreString(bestScore, worstScore, averageScore);
    }
}

private static int numberOfUs(String board, char playerChar) {
    int us = 0;

    for (int i = 0; i < board.length(); i++ ) {
         if (board.charAt(i) == playerChar) {
            us++;
        }
    }

    return us;
}

private static float calculateScore(String board, int roundsPassed) {
    int empties = 0;
    int us = 0;
    int enemy1 = 0;
    int enemy2 = 0;
    int enemy3 = 0;
    for (int i = 0; i < board.length(); i++ ) {
        if (board.charAt(i) == '.') {
            empties++;
        } else if (board.charAt(i) == Integer.toString(me).charAt(0)) {
            us++;
        } else if (board.charAt(i) == Integer.toString(me%PLAYERS + 1).charAt(0)) {
            enemy1++;
        } else if (board.charAt(i) == Integer.toString(me%PLAYERS + 2).charAt(0)) {
            enemy2++;
        } else if (board.charAt(i) == Integer.toString(me%PLAYERS + 3).charAt(0)) {
            enemy3++;
        }
    }

    if (us != 0) {
        us += roundsPassed;
    }

    if (enemy1 != 0) { 
        enemy1 = enemy1 + (roundsPassed + 3)%PLAYERS;
    }

    if (enemy2 != 0) { 
        enemy2 = enemy2 + (roundsPassed + 2)%PLAYERS;
    }

    if (enemy3 != 0) { 
        enemy3 = enemy3 + (roundsPassed + 1)%PLAYERS;
    }

    return us*(empties + 1)/(Math.max(Math.max(enemy1, enemy2), enemy3) + 1);
}

private static float getScore(String scoreString) {
    float bestScore, worstScore, averageScore;
    String[] scores = new String[3];

    scores = scoreString.split(",");
    bestScore = Float.parseFloat(scores[0]);
    worstScore = Float.parseFloat(scores[1]);
    averageScore = Float.parseFloat(scores[2]);


    return (float) Math.sqrt(Math.sqrt(bestScore*averageScore*worstScore*worstScore));
}

private static String getScoreString(float bestScore, float worstScore, float averageScore) {
    return Float.toString(bestScore) + ',' + Float.toString(worstScore) + ',' + Float.toString(averageScore);
}

private static boolean addIfUnique(String[] boards, String board, int checkedBoards) {
    int i = 0;

    while (i < boards.length && boards[i] != null) {
        if (boards[i].equals(board)) {
            return false;
        }
        i++;
    }

    if (i < boards.length) {
        boards[i] = board;
    } else {
        boards[checkedBoards%boards.length] = board;
    }

    return true;
}

private static String calculateMove(String board, String move) {
    int x1 = Integer.parseInt(Character.toString(move.charAt(0)));
    int y1 = Integer.parseInt(Character.toString(move.charAt(2)));
    int x2 = Integer.parseInt(Character.toString(move.charAt(4)));
    int y2 = Integer.parseInt(Character.toString(move.charAt(6)));

    if ((Math.abs(y1 - y2) == 2 || Math.abs(x1 - x2) == 2) 
            &&  getCharAt(board, x2, y2) == '.') {
        Point[] enemies = new Point[8];

        enemies = getNeighboringEnemies(board, new Point(x1, y1), Integer.parseInt(Character.toString(getCharAt(board, x1, y1))));

        board = replace(board, enemies, getCharAt(board, x1, y1));
        Point[] middle = {new Point(x1, y1)};
        board = replace(board, middle, '.');
    }

    if ((Math.abs(y1 - y2) == 1 || Math.abs(x1 - x2) == 1)) { 
        if (getCharAt(board, x2, y2) == '.' || getCharAt(board, x1, y1) == getCharAt(board, x2, y2)) {
            boolean merge = true;
            if (getCharAt(board, x2, y2) == '.') {
                merge = false;
            }

            Point[] spaces = new Point[8];
            spaces = getNeighboringMatches(board, new Point(x1, y1), '.');
            board = replace(board, spaces, getCharAt(board, x1, y1));

            if (merge) {
                Point[] source = {new Point(x1, y1)};
                board = replace(board, source, '.');
            }
        }
    }

    return board;
}

private static String replace(String board, Point[] targets, char source) {
    int i = 0;

    while (i < targets.length && targets[i] != null) {
        if (targets[i].x == 7 && targets[i].y == 7) {
            board = board.substring(0, getIndexAt(targets[i].x, targets[i].y)) + source;
        } else if (targets[i].x == 0 && targets[i].y == 0) {
            board = source + board.substring(getIndexAt(targets[i].x, targets[i].y) + 1);
        } else {
            board = board.substring(0, getIndexAt(targets[i].x, targets[i].y)) + source + board.substring(getIndexAt(targets[i].x, targets[i].y) + 1);
        }
        i++;
    }

    return board;
}

private static Point[] getNeighboringMatches(String board, Point coord, char match) {
    Point[] matches = new Point[8];

    int i = 0;
    for (int x = coord.x - 1; x <= coord.x + 1; x++) {
        for (int y = coord.y - 1; y <= coord.y + 1; y++) {
            if ((y != coord.y || x != coord.x ) && getCharAt(board, x, y) == match){
                matches[i] = new Point(x, y);
                i++;
            }
        }
    }

    return matches;
}

private static Point[] getNeighboringEnemies(String board, Point coord, int player) {
    Point[] enemies = new Point[8];

    for (int i = 1; i <= PLAYERS; i++){
        enemies = mergeArr(enemies, getNeighboringMatches(board, coord, Integer.toString((player + i - 1)%PLAYERS + 1).charAt(0)));
    }

    return enemies;
}

private static Point[] getNextNeighboringMatches(String board, Point coord, char match) {
    Point[] matches = new Point[16];

    int i = 0;
    for (int x = coord.x - 2; x <= coord.x + 2; x++) {
        for (int y = coord.y - 2; y <= coord.y + 2; y++) {
            if ((Math.abs(y - coord.y) == 2 || Math.abs(x - coord.x) == 2) && getCharAt(board, x, y) == match){
                matches[i] = new Point(x, y);
                i++;
            }
        }
    }

    return matches;
}

private static char getCharAt(String board, int x, int y) {

    if (x >= 0 && x < 8 && y >= 0 && y < 8) {
        return board.charAt(9*x + y);
    } else {
        return '\0';
    }
}

private static int getIndexAt(int x, int y) {
    return 9*x + y;
}

private static Point[] mergeArr(Point[] arr1, Point[] arr2) {
    int i = 0;
    int j = 0;

    while (i < arr1.length && arr1[i] != null) {
        i++;
    }

    while (j < arr2.length && arr2[j] != null) {
        arr1[i + j] = arr2[j];
        j++;
    }

    return arr1;
}

private static String getMove(int x1, int y1, int x2, int y2) {
    return Integer.toString(x1) + " " + Integer.toString(y1) + " " + Integer.toString(x2) + " " + Integer.toString(y2);
    }
}

मैं बहुत प्रोग्रामर नहीं हूं और यह तरीका मेरे द्वारा अनुमानित किए जाने से अधिक जटिल था, मैंने इस कोड का अभी तक परीक्षण नहीं किया है (बिल्कुल भी) क्योंकि यह 3 बजे है और मुझे कल जल्दी काम करने की आवश्यकता है। यह काफी संभव है कि मेरे बॉट समय से बाहर हो जाएंगे या बस काम नहीं करेंगे। मैंने भी निर्देशकों को गलत पाया होगा, मैं कल इसे एक और नज़र के साथ ताज़े आँखों से देखूँगा, लेकिन एक अतिरिक्त जोड़ी (या अधिक) का हमेशा स्वागत है, एक अतिरिक्त जोड़ी (अधिक अनुभवी) आँखें हैं।
ओवरएक्टर

मुझे इसके लिए अपवादों का एक समूह मिल रहा है ( स्टैकट्रेस के लिए चैट देखें )।
दरवाज़े

मेरा कोड आखिरकार चल रहा है, लेकिन मुझे गति की सख्त आवश्यकता है ताकि मैं उन शाखाओं के प्रतिशत को कम कर सकूं जिन्हें मैं छोड़ता हूं। क्या किसी को पता है कि इस गंदगी को कैसे सुधारें?
ओवरएक्टर जूल 22'14

चूँकि यह गोल्फ नहीं है, आप इसे कोड रिव्यू पर पोस्ट कर सकते हैं ... क्या यह नियमों के भीतर होगा या इसे फालो किया जाएगा?
ट्राइकोप्लाक्स

1
मैंने इसका उत्तर दो दिन पहले देखा था, लेकिन मुझे सिर्फ यह महसूस हुआ कि "शाल्लो ब्लू" प्रसिद्ध "डीप ब्लू" के लिए एक सजा है।
औचित्य

2

उछलनेवाला

कूदना पसंद करता है, और भी अधिक मध्य की ओर।

पास होगा अगर कोई स्लैम नहीं कूद सकता।

सी ++ , बस के साथ संकलन करना चाहिएg++ jumper.cpp -o jumper

#include <math.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#define maxn(x, y) ((x) > (y) ? (x) : (y))
#define absn(x) ((x) < 0 ? -(x) : (x))
class Board {
 public:
    Board(std::string input_string);
    void Move();
 private:
    void ParseBoardState(std::string console_string);
    int Slimes(int cell);
    void GetXY(int cell, int& r, int& c);
    bool CanJumpFromHere(int cell, int& jump_to_cell, int& rad);
    int CalcRadius(int cell);
    bool CheckJumpDist(int x, int y);

    int player_num_;
    std::size_t board_dim_;
    std::size_t sq_;
    std::vector< std::vector<int> > slimes_;
};
Board::Board(std::string input_string) 
    : player_num_(0), 
      board_dim_(0),
      slimes_() {
    board_dim_ = std::count(input_string.begin(), input_string.end(), ',');
    sq_ = board_dim_ * board_dim_;
    std::istringstream temp(input_string.substr(0,1));
    temp >> player_num_;
    ParseBoardState(input_string);
}
void Board::ParseBoardState(std::string console_string) {
    int place = 0;
    for (std::size_t row = 0; row < board_dim_; ++row ) {
        slimes_.push_back(std::vector<int>());
        place = console_string.find(",",place+1);
        std::string temp2 = console_string.substr(place+1, 8);
        for (std::size_t col = 0; col < board_dim_; ++col ) {
            int sl = 0;
            std::istringstream bint(temp2.substr(col,1));
            bint >> sl;
            slimes_[row].push_back(sl);
        }
    }
}
int Board::Slimes(int cell) {
    int r = 0;
    int c = 0;
    GetXY(cell, r, c);
    return  slimes_[r][c];
}
void Board::GetXY(int cell, int& r, int& c) {
    for (std::size_t row = 0; row < board_dim_; ++row ) {
        for (std::size_t col = 0; col < board_dim_ ; ++col ) {
            if ( (row * board_dim_ + col) == cell) {
                r = row;
                c = col;
            }
        }
    }
}
void Board::Move() {

    // go through each cell:
    int index = 0;
    int jump_to_cell = 0;
    int rad = 0;
    int min_rad = 1000;
    int best_jump_to = -1;
    int best_jump_from = -1;
    for (int c = 0; c < sq_; ++c) {
        if (Slimes(c) == player_num_) {
            if (CanJumpFromHere(c, jump_to_cell , rad)) {
                if (rad < min_rad) {
                    best_jump_from = c;
                    best_jump_to = jump_to_cell;
                    min_rad = rad;
                }
                index += 1;
            }
        }
    }

    int ret_row = 0;
    int ret_col = 0;

    if (index == 0) {
        // can't jump so dont bother:
        std::cout << "0 0 0 0" << std::endl;
    } else {
        GetXY(best_jump_from, ret_row, ret_col);
        std::cout << ret_row << " " << ret_col  << " ";
        GetXY(best_jump_to, ret_row, ret_col);
        std::cout << ret_row << " " << ret_col << std::endl;
    }
}
bool Board::CanJumpFromHere(int cell, int& ret_jump_to_cell, int & ret_rad) {
    int r = 0;
    int c = 0;
    int rad = 10000;
    int jump_to_cell = 0;
    int rad_min_for_this_cell = 10000;
    GetXY(cell, r, c);
    bool jumpable = false;
    for (int row_test = -2; row_test < 3; ++row_test) {
        for (int col_test = -2; col_test < 3; ++col_test) {
            if ( (r + row_test) > 0 &
                 (r + row_test) < board_dim_ &&
                 (c + col_test) > 0 &&
                 (c + col_test) < board_dim_ &&
                 (CheckJumpDist(col_test, row_test)) &&
                 (slimes_[r+row_test][c+col_test] == 0)) {

                jumpable = true;
                jump_to_cell = (r + row_test) * board_dim_ + c + col_test;
                rad = CalcRadius(jump_to_cell);

                if (rad < rad_min_for_this_cell) {
                    ret_rad = rad;
                    ret_jump_to_cell = jump_to_cell;
                    rad_min_for_this_cell = ret_rad;
                }
            }
        }
    }
    return jumpable;
}
bool Board::CheckJumpDist(int x, int y) {
    int maxDelta = maxn(absn(x), absn(y));
    if (maxDelta <= 0 || maxDelta > 2) {
        return false;
    } else {
        return true;
    }
}
int Board::CalcRadius(int cell) {
    int r = 0;
    int c = 0;
    GetXY(cell, r, c);
    // unnecessary accuracy considering how bad this bot is:
    float mid = static_cast<float>(board_dim_) / 2;
    float rad = sqrt((r - mid) * (r - mid) + (c-mid)*(c-mid));
    int ret = static_cast<int>(rad + 0.5);
    return ret;
}
int main(int argc, char* argv[]) {
    if (argc != 2) {
        return 0;
    } else {
        std::string input_string(argv[1]);
        Board board(input_string);
        board.Move();
    }
    return 0;
}

मैंने आपका कदम सत्यापन क्षमा कर दिया। इसके अलावा, मैंने शुरू करने के बाद सही कोडिंग प्रथाओं को छोड़ दिया, इसलिए मत देखो। हालाँकि, यह बोर्ड के किसी भी आकार पर चलता है।


2

डेथस्लाइम :

विवरण : सबसे कमजोर दुश्मन का शिकार करने और उन्हें नष्ट करने की कोशिश करता है। दोहराएँ।

कैसे चलाएं : रूबी डेथस्लाइम.आरबी

रूबी संस्करण : 2.1.2

#!/usr/bin/env ruby
class PlayerPosition;
  attr_accessor :x, :y;
  def initialize(x, y) @x = x; @y = y; end
  def distance(pos) Math.sqrt((pos.x - @x)**2 + (pos.y - @y)**2); end
end

class Board
  attr_reader :player, :empty_positions
  def initialize(player_id, game_state_string)
    @player_positions = {}
    @empty_positions = []

    @enemies = []
    @player = Player.new

    row = 0
    col = 0
    game_state_string.chars.each do |tile|
      row += 1 and col = 0 and next if tile == ','
      @empty_positions << PlayerPosition.new(col, row) and col += 1 and next if tile == '.'

      @player_positions[tile] ||= []
      @player_positions[tile] << PlayerPosition.new(col, row)
      col += 1
    end

    @player_positions.each do |id, positions|
      @enemies << Player.new(id, positions) if id != player_id
      @player = Player.new(id, positions) if id == player_id
    end
  end

  def border_space(player_positions, possible_border, allowance = 1)
    near = []
    possible_border.each do |border|
      is_near = false
      player_positions.each {|pos| is_near = true and break if pos.distance(border) <= allowance}
      near << border if is_near
    end
    near
  end

  def closest_to(player_positions, enemy_positions)
    player_closest_block = nil
    shortest_distance = 1000
    enemy_closest_block = nil
    player_positions.each do |player|
      enemy_positions.each do |enemy|
        if player.distance(enemy) < shortest_distance
          shortest_distance = player.distance(enemy)
          enemy_closest_block = enemy
          player_closest_block = player
        end
      end
    end
    return player_closest_block, enemy_closest_block
  end

  def empty_space_near(player_positions, allowance = 1); border_space(player_positions, @empty_positions, allowance); end
  def weakest_enemy; @enemies.select{|enemy| !enemy.dead? }.sort {|x,y| x.strength <=> y.strength}.first; end
end

class Player
  attr_reader :positions
  def initialize(id = -1, positions = []); @id = id; @positions = positions; end
  def dead?; @positions.length == 0; end
  def strength; @positions.length; end
  def can_hurt?(enemy)
    is_close_enough = false
    self.positions.each do |my_pos|
      enemy.positions.each {|enemy_pos| is_close_enough = true and break if my_pos.distance(enemy_pos) <= 2 }
    end
    is_close_enough
  end
end




class DeathSlime

  def initialize(arg_string)
    game_state = arg_string[2..-1]
    player_id = arg_string[0]
    @board = Board.new(player_id, game_state)
  end

  def attack
    if @board.weakest_enemy
      try_to_spread_to_weakest || try_to_jump_to_weakest || try_to_merge_to_weakest || try_to_move_to_weakest
    else
      try_to_move if @empty_positions.length > 0
    end
  end


  def try_to_spread_to_weakest
    mine = @board.empty_space_near(@board.player.positions, 1)
    theirs = @board.empty_space_near(@board.weakest_enemy.positions, 1)
    target_space = mine.detect{|space| theirs.include?(space) }
    return move(@board.closest_to(@board.player.positions, [target_space]).first, target_space) if target_space
    false
  end

  def try_to_jump_to_weakest
    mine = @board.empty_space_near(@board.player.positions, 2)
    theirs = @board.empty_space_near(@board.weakest_enemy.positions, 1)
    target_space = mine.detect{|space| theirs.include?(space) }
    return move(@board.closest_to(@board.player.positions, [target_space]).first, target_space) if target_space
    false
  end

  def try_to_merge_to_weakest
    definite_border = nil
    definite_merge = nil
    possible_border = @board.border_space(@board.weakest_enemy.positions, @board.player.positions)
    possible_border.each do |border|
      possible_merges = @board.border_space([ border ], @board.player.positions.select{|space| space != border })
      definite_merge = possible_merges.first and definite_border = border and break if possible_merges.length > 0
    end
    return move(definite_merge, definite_border) if definite_border && definite_merge
    false
  end

  def try_to_move_to_weakest
    player_closest, enemy_closest = @board.closest_to(@board.player.positions, @board.weakest_enemy.positions)
    spreading_distance = @board.empty_space_near([player_closest], 1)
    jumping_distance = @board.empty_space_near([player_closest], 2)
    theirs = @board.empty_space_near(@board.player.positions, 2)

    spreading_space = spreading_distance.detect{|space| theirs.include?(space) }
    return move(@board.closest_to(@board.player.positions, [spreading_space]).first, spreading_space) if spreading_space

    jumping_space = jumping_distance.detect{|space| theirs.include?(space) }
    return move(@board.closest_to(@board.player.positions, [jumping_space]).first, jumping_space) if jumping_space

    return move(@board.closest_to(@board.player.positions, [spreading_distance]).first, spreading_distance) if spreading_distance.length > 0
    return move(@board.closest_to(@board.player.positions, [jumping_distance]).first, jumping_distance) if jumping_distance.length > 0

    #merge randomly
    closest_enemy = @board.closest_to(@board.player.positions, @board.weakest_enemy.positions).first
    return move(@board.closest_to(@board.player.positions.select{|space| space != closest_enemy }, [closest_enemy]).first, closest_enemy)
  end

  def try_to_move
    spreading_distance = @board.empty_space_near(board.player.positions, 1)
    jumping_distance = @board.empty_space_near(board.player.positions, 2)

    return move(@board.closest_to(@board.player.positions, [spreading_distance]).first, spreading_distance) if spreading_distance.length > 0
    return move(@board.closest_to(@board.player.positions, [jumping_distance]).first, jumping_distance) if jumping_distance.length > 0
  end

  def move(start_block, end_block)
    STDOUT.write "#{start_block.x} #{start_block.y} #{end_block.x} #{end_block.y}"
    true
  end
end

slime_of_death = DeathSlime.new(ARGV[0])
slime_of_death.attack

1

काई

यह R में लिखा गया एक बॉट है। इसका उपयोग करके ट्रिगर करने की आवश्यकता है Rscript Lichen.R

input <- strsplit(commandArgs(TRUE),split=",")[[1]]
me <- input[1]
arena <- do.call(rbind,strsplit(input[-1],""))
n <- sum(arena==me)
where <- which(arena==me,arr.ind=TRUE)
closest <- function(a,b){
    x <- abs(outer(a[,1],b[,1],`-`))
    y <- abs(outer(a[,2],b[,2],`-`))
    matrix(which(x<2&y<2,arr.ind=TRUE),ncol=2)
    }
if(n==0){ #No slime on the board
    out <- "0 0 0 0"
    }else if(n==1){ #One slime on the board
        x <- where[1]+c(1,-1)
        y <- where[2]+c(1,-1)
        out <- paste(where[1]-1,where[2]-1,x[x%in%2:(nrow(arena)-1)]-1,y[y%in%2:(nrow(arena)-1)]-1,sep=" ")
    }else{
        area <- apply(which(arena==me,arr.ind=TRUE),2,range,na.rm=TRUE)
        empty <- matrix(which(arena==".",arr.ind=TRUE),ncol=2)
        opponents <- c("1","2","3","4")[c("1","2","3","4")!=me]
        for(i in seq_along(opponents)){
            if(i==1){
                other <- which(arena==opponents[i],arr.ind=TRUE)
                }else{other <- rbind(other,which(arena==opponents[i],arr.ind=TRUE))}
            }
        fillable <- matrix(empty[empty[,1]%in%area[1,1]:area[2,1]&empty[,2]%in%area[1,2]:area[2,2],],ncol=2)
        enemies <- matrix(other[other[,1]%in%area[1,1]:area[2,1]&other[,2]%in%area[1,2]:area[2,2],],ncol=2)
        if(length(unique(where[,2]))==1 | length(unique(where[,2]))==1){ #Slimes form a line
            W <- closest(where,empty)
            if(nrow(W)){
                out <- paste(c(where[W[1,1],]-1,empty[W[1,2],]-1),collapse=" ")
            }else{out <- "0 0 0 0"}
        }else if(length(enemies)&length(fillable)){ #There are enemies and empty spaces in habitable area
            w <- closest(enemies, fillable)
            if(nrow(w)){
                X <- abs(where[,1]-fillable[w[1,2],1])
                Y <- abs(where[,2]-fillable[w[1,2],2])
                W <- which(X<2&Y<2)
                out <- paste(c(where[W[1],]-1,fillable[w[1,2],]-1),collapse=" ")
            }else{out <- "0 0 0 0"}
        }else if(length(fillable)){ #There are empty spaces in habitable area
            w <- closest(fillable,where)
            out <- paste(c(where[w[1,2],]-1,fillable[w[1,1],]-1),collapse=" ")
        }else{
            x <- area[!area[,1]%in%c(1,nrow(arena)),1]
            y <- area[!area[,2]%in%c(1,ncol(arena)),2]
            if(sum(arena[x+(-1:1),y+(-1:1)]==".")>1){
                w <- where[where[,1]%in%(x+c(1,-1))&where[,2]%in%(y+c(1,-1)),]
                out <- paste(w[1]-1,w[2]-1,x-1,y-1,sep=" ")
            }else{
                W <- closest(where, empty)
                if(nrow(W)){
                    out <- paste(c(where[W[1,1],]-1,empty[W[1,2],]-1),collapse=" ")
                }else{out <- "0 0 0 0"}
            }
        }
    }
cat(out)

अभिप्रेरित एल्गोरिथ्म यह है कि यह एक आयताकार क्षेत्र (रिक्त का उपयोग करके भरना spread) को कवर करने की कोशिश करता है । जब आयत पूरा हो जाता है, तो यह merges"रहने योग्य" क्षेत्र का विस्तार करने के लिए इसके कोने में से एक (बोर्ड के कोने से एक सबसे दूर) पर दो स्लाइस करता है, फिर उस नए परिभाषित आयत आदि को भरें jump

.....   .....   .....   .....   .....   ..333
.....   .333.   3333.   3333.   3333.   33333
333..   3333.   3333.   3333.   3333.   33.33
333..   3.33.   3.33.   3333.   3333.   3333.
333..   333..   333..   333..   3333.   3333.

यदि कोई दुश्मन रहने योग्य क्षेत्र में है और क्षेत्र में एक खाली जगह है, तो यह उसके बगल में खाली जगह को भरता है। यदि निवास योग्य क्षेत्र का विस्तार करते समय जो कीचड़ को मिलाया जाना चाहिए, वह दुश्मनों से घिरा हुआ है, तो एक कीचड़ केवल spreadइस एक विलय के बजाय होगा ।


मुझे इसके लिए त्रुटियों का एक समूह मिल रहा है ( स्टैकट्रेस के लिए चैट देखें )।
दरवाज़े

बॉट अब भेजते हैं 0 0 0 0जब कोई कीचड़ बोर्ड पर नहीं रहता है।
प्लेनैपस जूल

0

CornerSlime

इस कीचड़ में कोनों की एक धारणा है, या कम से कम जब मैंने पहली बार इसे सी # में लिखा था, तो मैं वास्तव में किसी भी अधिक निश्चित नहीं हूं।

C ++ में लिखा गया है, संभवतः gcc के साथ ठीक संकलित किया जाएगा और बिना किसी तर्क के; उम्मीद है कि मैंने दुर्घटना से MSVC के विशिष्ट उपयोग नहीं किया है।

विशेष रूप से संशोधित सर्वर पर स्वयं के खिलाफ परीक्षण किया गया (कोई फैंसी नया सी ++ संकलक जहां मैं हूं) तो मुझे कोई सुराग नहीं है कि यह कैसे प्रदर्शन करेगा, उम्मीद है कि यह बहुत धीमी गति से होने के लिए अयोग्य नहीं होगा। वर्तमान में इस बॉट में कोई यादृच्छिकता नहीं है, लेकिन मैं बाद की तारीख में कुछ जोड़ सकता हूं।

यह C # है जिसे C ++ में पोर्ट किया गया है (गति संबंधी चिंताओं के कारण) जो वास्तव में C ++ नहीं जानता है, और भयावह है। यह कोशिकाओं की एक सरणी का निर्माण करके शुरू होता है, जो तब इसके चारों ओर की कोशिकाओं के बारे में सभी प्रकार की अनछुई जानकारी से भर जाता है (मेरी कोशिकाओं की संख्या, मेरे कातिलों की संख्या, उस तरह की चीज)। फिर यह इस जानकारी का उपयोग यह तय करने के लिए करता है कि क्या यह उस जानकारी को बनाने के लिए उपयोग की जाने वाली जानकारी पर अधिक बारीकी से देखने की जरूरत है, और फिर संभावित रूप से उक्त जानकारी का उपयोग सार्थक उत्पादन करने के लिए करता है।

#include <iostream>

#define min(a,b) a>b?b:a;
#define max(a,b) a>b?a:b;

#define null 0 // fun times

struct Cell
{
public:
    int t;
    int x, y;
    int counts1[5];
    int counts2[5];
    int ecount1;
    int ecount2;
    bool safe1;
    bool safe2;

    bool canspread;
    bool canjump;
    bool canmerge;

    bool spreadable;
    bool jumpable;
    bool mergeable;

    Cell()
    {
        for (int i = 0; i < 5; i++)
        {
            counts2[i]=counts1[i]=0;
        }
        ecount1=ecount2=0;
        safe1=safe2=mergeable=jumpable=spreadable=canmerge=canjump=canspread=false;
    }

    Cell(int tN, int xN, int yN) // not sure why I can't call () constructor here
    {
        for (int i = 0; i < 5; i++)
        {
            counts2[i]=counts1[i]=0;
        }
        ecount1=ecount2=0;
        safe1=safe2=mergeable=jumpable=spreadable=canmerge=canjump=canspread=false;

        t = tN;
        x = xN;
        y = yN;
    }

    void findOptions(int moi)
    {
        if (t == 0)
        {
            if (counts1[moi] > 0)
                spreadable = true;
            if (counts2[moi] > 0)
                jumpable = true;
        }
        else if (t == moi)
        {
            if (counts1[moi] > 0)
                mergeable = canmerge = true;
            if (counts1[0] > 0)
                canspread = true;
            if (counts2[0] > 0)
                canjump = true;
        }
    }
};

const int dim = 8;
const int hdim = 4;

int moi;
int chezMoi;

int target;
int chezTarget;

Cell cells[dim][dim];

int cornerCounts[4][5];
int totalCounts[5];

// ring ness - why why why

// end ring ness

int tlx;
int tly;
int thx;
int thy;

int alx;
int aly;
int ahx;
int ahy;

int rj;
int rstate;

void ring(int x, int y, int dist)
{   
    tlx=x-dist;
    tly=y-dist;
    thx=x+dist;
    thy=y+dist;

    alx=max(0, tlx);
    aly=max(0, tly);
    ahx=min(dim-1, thx);
    ahy=min(dim-1, thy);

    rstate = 0;
}

bool nextR(Cell** outc)
{
    if (rstate == 1)
    {
        goto state1;
    }
    if (rstate == 2)
    {
        goto state2;
    }
    if (rstate == 3)
    {
        goto state3;
    }
    if (rstate == 4)
    {
        goto state4;
    }

    if (alx == tlx)
    {
        rj = aly - 1;
        rstate = 1;
    }
state1:
    if (alx == tlx)
    {
        if (++rj <= ahy)
        {
            *outc = (cells[alx]+rj);
            return true;
        }
        alx++;
    }

    if (ahx == thx)
    {
        rj = aly - 1;
        rstate = 2;
    }
state2:
    if (ahx == thx)
    {
        if (++rj <= ahy)
        {
            *outc = (cells[ahx]+rj);
            return true;
        }
        ahx--;
    }

    if (aly == tly)
    {
        rj = alx - 1;
        rstate = 3;
    }
state3:
    if (aly == tly)
    {
        if (++rj <= ahx)
        {
            *outc = (cells[rj]+aly);
            return true;
        }
    }

    if (ahy == thy)
    {
        rj = alx - 1;
        rstate = 4;
    }
state4:
    if (ahy == thy)
    {
        if (++rj <= ahx)
        {
            *outc = (cells[rj]+ahy);
            return true;
        }
    }

    return null;
}

int cox;
int coy;

int ci;
int cj;

void corner(int idx)
{
    cox = (idx / 2) * hdim;
    coy = (idx % 2) * hdim;

    ci = 0;
    cj = -1;
}

bool nextC(Cell** outc)
{
    for (;ci < hdim;ci++)
    {
        for (;++cj < hdim;)
        {
            *outc = (cells[ci+cox]+cj+coy);
            return true;
        }
        cj = -1;
    }

    return false;
}

void cornerCount(int idx, int* c)
{
    int ox = (idx / 2) * hdim;
    int oy = (idx % 2) * hdim;

    for (int i = 0; i < hdim; i++)
    {
        for (int j = 0; j < hdim; j++)
        {
            c[cells[i+ox][j+oy].t]++;
        }
    }
}

void ringCount(int x, int y, int dist, int* c)
{
    int tlx=x-dist;
    int tly=y-dist;
    int thx=x+dist;
    int thy=y+dist;

    int alx=max(0, tlx);
    int aly=max(0, tly);
    int ahx=min(dim-1, thx);
    int ahy=min(dim-1, thy);

    if (alx == tlx)
    {
        for (int j = aly; j <= ahy; j++)
            c[cells[alx][j].t]++;
        alx++;
    }
    if (ahx == thx)
    {
        for (int j = aly; j <= ahy; j++)
            c[cells[ahx][j].t]++;
        ahx--;
    }
    if (aly == tly)
    {
        for (int i = alx; i <= ahx; i++)
            c[cells[i][aly].t]++;
    }
    if (ahy == thy)
    {
        for (int i = alx; i <= ahx; i++)
            c[cells[i][ahy].t]++;
    }
}

int trans(char c)
{
    return c<48?0:c-48;
}

std::string res(Cell* ca, Cell* cb)
{
    char buff[100]; // shhh
    sprintf_s(buff, "%d %d %d %d\n", ca->x, ca->y, cb->x, cb->y);
    return std::string(buff);
}

std::string go(char* inp)
{
    moi = trans(inp[0]);

    int a = 2;

    for (int i = 0; i < dim; i++)
    {
        for (int j = 0; j < dim; j++)
        {
            cells[i][j] = Cell(trans(inp[a]), i, j);
            a++;
        }
        a++;
    }

    // count corners and totals
    for (int i = 0; i < 4; i++)
    {
        cornerCount(i, cornerCounts[i]);
        for (int j = 0; j < 5; j++)
        {
            totalCounts[j] += cornerCounts[i][j];
        }
    }

    // count and find cell options
    for (int i = 0; i < dim; i++)
    {
        for (int j = 0; j < dim; j++)
        {
            Cell* c = cells[i]+j;

            ringCount(i, j, 1, c->counts1);
            ringCount(i, j, 2, c->counts2);

            // safeness
            for (int r = 1; r < 5; r++)
            {
                if (r != moi)
                {
                    c->ecount1 += c->counts1[r];
                    c->ecount2 += c->counts2[r];
                }
            }
            c->safe1 = c->ecount1 == 0 && c->counts1[0] == 0; // surrounded by moi
            c->safe2 = c->ecount1 == 0 && c->ecount2 == 0; // no enemies in sight

            // that funcion which does stuff
            c->findOptions(moi);
        }
    }

    // find chezMoi
    chezMoi = moi-1; // might work, can't be bothered to work it out
    for (int i = 1; i < 4; i++)
    {
        if (cornerCounts[i][moi] > cornerCounts[chezMoi][moi])
            chezMoi = i;
    }

    int best = 0;

    if (cornerCounts[chezMoi][moi] < hdim * hdim)
    {
        // fill our corner
        best = 0;
        Cell* ac = null;
        Cell* bc = null;

        corner(chezMoi);
        Cell* c;
        while (nextC(&c))
        {
            if (c->spreadable && c->ecount1 + 1 > best)
            {
                ring(c->x, c->y, 1);
                Cell* oc;
                while (nextR(&oc))
                {
                    if (oc->canspread)
                    {
                        best = c->ecount1 + 1;
                        ac = oc;
                        bc = c;
                        break;
                    }
                }
            }
            if (c->mergeable && c->counts1[0] - 1 > best)
            {
                ring(c->x, c->y, 1);
                Cell* oc;
                while (nextR(&oc))
                {
                    if (oc->safe2 && oc->canmerge && c->counts1[0] > 0)
                    {
                        best = c->counts1[0] - 1;
                        ac = oc;
                        bc = c;
                        break;
                    }
                }
            }
        }

        if (bc != null)
        {
            return res(ac, bc);
        }
    }

    // pick target (why?)
    target = -1;
    best = 0;
    for (int i = 0; i < 4; i++)
    {
        if (i == moi)
            continue;
        int cur = totalCounts[i];
        if (target == -1 || cur > best)
        {
            target = i;
            best = cur; 
        }
    }

    if (target != -1)
    {
        for (int i = 0; i < 4; i++)
        {
            if (i == chezMoi)
                continue;
            int cur = cornerCounts[i][target];
            if (chezTarget == -1 || cur > best)
            {
                chezTarget = i;
                best = cur;
            }
        }

        // attack chosen target (not sure it does this anymore...)
        best = 0;
        Cell* ac = null;
        Cell* bc = null;

        for (int i = 0; i < dim; i++)
        {
            for (int j = 0; j < dim; j++)
            {
                Cell* c = cells[i]+j;

                if (c->spreadable && c->ecount1 + 1 > best)
                {
                    ring(c->x, c->y, 1);
                    Cell* oc;
                    while (nextR(&oc))
                    {
                        if (oc->canspread)
                        {
                            best = c->ecount1 + 1;
                            ac = oc;
                            bc = c;
                            break;
                        }
                    }
                }
                if (c->jumpable && c->ecount1 - 1 > best)
                {
                    ring(c->x, c->y, 2);
                    Cell* oc;
                    while (nextR(&oc))
                    {
                        if (oc->safe2 && oc->canjump)
                        {
                            best = c->ecount1 - 1;
                            ac = oc;
                            bc = c;
                            break;
                        }
                    }
                }
            }
        }

        if (bc != null)
        {
            return res(ac, bc);
        }
    }

    return "0 0 0 0\n";
}

int main(int argc, char* args[])
{
    printf(go(args[1]).c_str());
    return 0;
}
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.